@bedard/hexboard 0.0.8 → 0.0.9
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/CHANGELOG.md +5 -0
- package/dist/index.js +289 -296
- package/package.json +1 -1
- package/src/lib/components/hexboard/Hexboard.vue +6 -0
- package/src/tests/hexboard.test.tsx +56 -40
- package/src/tests/utils.ts +28 -2
- package/vite.config.ts +18 -1
package/CHANGELOG.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
import { defineComponent as ao, createElementBlock as P, openBlock as b, createElementVNode as fo, toDisplayString as vo, mergeModels as so, useModel as Zt, shallowRef as tt, useTemplateRef as Co, computed as
|
|
2
|
-
import { Hexchess as co, position as
|
|
3
|
-
function r(
|
|
4
|
-
return [
|
|
1
|
+
import { defineComponent as ao, createElementBlock as P, openBlock as b, createElementVNode as fo, toDisplayString as vo, mergeModels as so, useModel as Zt, shallowRef as tt, useTemplateRef as Co, computed as A, onMounted as Eo, onUnmounted as Lo, watch as ro, createCommentVNode as ot, unref as a, normalizeStyle as at, Fragment as nt, renderList as lt, mergeProps as Bo, createBlock as uo, resolveDynamicComponent as io, withModifiers as Mo, renderSlot as $o, h as To } from "vue";
|
|
2
|
+
import { Hexchess as co, position as fe, San as ft, isPromotionPosition as Fo } from "@bedard/hexchess";
|
|
3
|
+
function r(i, B, v) {
|
|
4
|
+
return [i[0] + v * (B[0] - i[0]), i[1] + v * (B[1] - i[1])];
|
|
5
5
|
}
|
|
6
|
-
function n(
|
|
7
|
-
return
|
|
6
|
+
function n(i) {
|
|
7
|
+
return i.map(t);
|
|
8
8
|
}
|
|
9
|
-
function e(
|
|
9
|
+
function e(i) {
|
|
10
10
|
return [
|
|
11
|
-
x(
|
|
12
|
-
x(
|
|
13
|
-
x(
|
|
14
|
-
x(
|
|
15
|
-
x(
|
|
16
|
-
x(
|
|
11
|
+
x(i, -300, ue),
|
|
12
|
+
x(i, 0, ue),
|
|
13
|
+
x(i, -60, ue),
|
|
14
|
+
x(i, -120, ue),
|
|
15
|
+
x(i, -180, ue),
|
|
16
|
+
x(i, -240, ue)
|
|
17
17
|
];
|
|
18
18
|
}
|
|
19
|
-
function x(
|
|
20
|
-
const
|
|
19
|
+
function x(i, B, v) {
|
|
20
|
+
const Q = Ro(B);
|
|
21
21
|
return [
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
v * Math.cos(Q) + i[0],
|
|
23
|
+
v * Math.sin(Q) + i[1]
|
|
24
24
|
];
|
|
25
25
|
}
|
|
26
|
-
function Ro(
|
|
27
|
-
return
|
|
26
|
+
function Ro(i) {
|
|
27
|
+
return i * (Math.PI / 180);
|
|
28
28
|
}
|
|
29
|
-
function t(
|
|
30
|
-
return [-
|
|
29
|
+
function t(i) {
|
|
30
|
+
return [-i[0], -i[1]];
|
|
31
31
|
}
|
|
32
|
-
function l(
|
|
33
|
-
return [
|
|
32
|
+
function l(i, B) {
|
|
33
|
+
return [i[0] + B[0], i[1] + B[1]];
|
|
34
34
|
}
|
|
35
|
-
function
|
|
36
|
-
return
|
|
35
|
+
function ve(i) {
|
|
36
|
+
return de / 2 + i;
|
|
37
37
|
}
|
|
38
|
-
function
|
|
39
|
-
return
|
|
38
|
+
function he(i) {
|
|
39
|
+
return de / 2 - i;
|
|
40
40
|
}
|
|
41
|
-
const
|
|
41
|
+
const de = 23.6, So = {
|
|
42
42
|
colors: [
|
|
43
43
|
"oklch(0.9015 0.0729 70.7)",
|
|
44
44
|
"oklch(0.8366 0.1165 66.29)",
|
|
@@ -57,37 +57,37 @@ const he = 23.6, So = {
|
|
|
57
57
|
// red-500
|
|
58
58
|
targetColor: "oklch(63.7% 0.237 25.331)"
|
|
59
59
|
// red-500
|
|
60
|
-
}, qo = "b/qbk/n1b1n/r5r/ppppppppp/11/5P5/4P1P4/3P1B1P3/2P2B2P2/1PRNQBKNRP1 w - 0 1",
|
|
61
|
-
[2,
|
|
62
|
-
[1,
|
|
63
|
-
[0,
|
|
64
|
-
[1,
|
|
60
|
+
}, qo = "b/qbk/n1b1n/r5r/ppppppppp/11/5P5/4P1P4/3P1B1P3/2P2B2P2/1PRNQBKNRP1 w - 0 1", u = 1.7, V = 1.7, ue = 2 / Math.sqrt(3), p = ue * (Math.sqrt(3) / 2) * 2, w = p * 2, y = p * 3, k = p * 4, L = p * 5, m = [0, 0], D = x(m, 150, L), S = x(m, 150, k), H = x(m, 150, y), q = x(m, 150, w), $ = x(m, 150, p), T = x(m, 30, p), N = x(m, 30, w), O = x(m, 30, y), z = x(m, 30, k), X = x(m, 30, L), U = l(D, [0, -L]), Z = l(S, [0, -L]), pe = l(H, [0, -L]), me = l(q, [0, -L]), ge = l($, [0, -L]), we = l(m, [0, -L]), ye = l(T, [0, -L]), be = l(N, [0, -L]), xe = l(O, [0, -L]), j = l(z, [0, -L]), G = l(X, [0, -L]), I = l(D, [0, -k]), J = l(S, [0, -k]), ke = l(H, [0, -k]), Pe = l(q, [0, -k]), Ce = l($, [0, -k]), Ee = l(m, [0, -k]), Le = l(T, [0, -k]), Be = l(N, [0, -k]), Me = l(O, [0, -k]), _ = l(z, [0, -k]), ee = l(X, [0, -k]), $e = l(D, [0, -y]), Te = l(S, [0, -y]), vt = l(H, [0, -y]), ht = l(q, [0, -y]), dt = l($, [0, -y]), pt = l(m, [0, -y]), mt = l(T, [0, -y]), gt = l(N, [0, -y]), wt = l(O, [0, -y]), Fe = l(z, [0, -y]), Re = l(X, [0, -y]), Se = l(D, [0, -w]), qe = l(S, [0, -w]), yt = l(H, [0, -w]), bt = l(q, [0, -w]), xt = l($, [0, -w]), kt = l(m, [0, -w]), Pt = l(T, [0, -w]), Ct = l(N, [0, -w]), Et = l(O, [0, -w]), Ne = l(z, [0, -w]), ze = l(X, [0, -w]), We = l(D, [0, -p]), Ae = l(S, [0, -p]), Lt = l(H, [0, -p]), Bt = l(q, [0, -p]), Mt = l($, [0, -p]), $t = l(m, [0, -p]), Tt = l(T, [0, -p]), Ft = l(N, [0, -p]), Rt = l(O, [0, -p]), De = l(z, [0, -p]), He = l(X, [0, -p]), Oe = l(S, [0, p]), Xe = l(H, [0, p]), St = l(q, [0, p]), qt = l($, [0, p]), Nt = l(m, [0, p]), zt = l(T, [0, p]), Wt = l(N, [0, p]), Ye = l(O, [0, p]), Ke = l(z, [0, p]), Qe = l(H, [0, w]), Ve = l(q, [0, w]), At = l($, [0, w]), Dt = l(m, [0, w]), Ht = l(T, [0, w]), Ue = l(N, [0, w]), Ze = l(O, [0, w]), je = l(q, [0, y]), Ge = l($, [0, y]), Ot = l(m, [0, y]), Ie = l(T, [0, y]), Je = l(N, [0, y]), te = l($, [0, k]), oe = l(m, [0, k]), ne = l(T, [0, k]), le = l(m, [0, L]), o = [
|
|
61
|
+
[2, le, t(le), e(le), n(e(le))],
|
|
62
|
+
[1, te, t(te), e(te), n(e(te))],
|
|
63
|
+
[0, oe, t(oe), e(oe), n(e(oe))],
|
|
64
|
+
[1, ne, t(ne), e(ne), n(e(ne))],
|
|
65
65
|
[0, je, t(je), e(je), n(e(je))],
|
|
66
66
|
[2, Ge, t(Ge), e(Ge), n(e(Ge))],
|
|
67
|
-
[1,
|
|
68
|
-
[2,
|
|
69
|
-
[0,
|
|
67
|
+
[1, Ot, t(Ot), e(Ot), n(e(Ot))],
|
|
68
|
+
[2, Ie, t(Ie), e(Ie), n(e(Ie))],
|
|
69
|
+
[0, Je, t(Je), e(Je), n(e(Je))],
|
|
70
70
|
[2, Qe, t(Qe), e(Qe), n(e(Qe))],
|
|
71
71
|
[1, Ve, t(Ve), e(Ve), n(e(Ve))],
|
|
72
|
-
[0,
|
|
73
|
-
[2,
|
|
74
|
-
[0,
|
|
72
|
+
[0, At, t(At), e(At), n(e(At))],
|
|
73
|
+
[2, Dt, t(Dt), e(Dt), n(e(Dt))],
|
|
74
|
+
[0, Ht, t(Ht), e(Ht), n(e(Ht))],
|
|
75
75
|
[1, Ue, t(Ue), e(Ue), n(e(Ue))],
|
|
76
76
|
[2, Ze, t(Ze), e(Ze), n(e(Ze))],
|
|
77
77
|
[1, Oe, t(Oe), e(Oe), n(e(Oe))],
|
|
78
78
|
[0, Xe, t(Xe), e(Xe), n(e(Xe))],
|
|
79
|
-
[2,
|
|
80
|
-
[1,
|
|
81
|
-
[0,
|
|
82
|
-
[1,
|
|
83
|
-
[2,
|
|
79
|
+
[2, St, t(St), e(St), n(e(St))],
|
|
80
|
+
[1, qt, t(qt), e(qt), n(e(qt))],
|
|
81
|
+
[0, Nt, t(Nt), e(Nt), n(e(Nt))],
|
|
82
|
+
[1, zt, t(zt), e(zt), n(e(zt))],
|
|
83
|
+
[2, Wt, t(Wt), e(Wt), n(e(Wt))],
|
|
84
84
|
[0, Ye, t(Ye), e(Ye), n(e(Ye))],
|
|
85
85
|
[1, Ke, t(Ke), e(Ke), n(e(Ke))],
|
|
86
86
|
[0, D, t(D), e(D), n(e(D))],
|
|
87
87
|
[2, S, t(S), e(S), n(e(S))],
|
|
88
88
|
[1, H, t(H), e(H), n(e(H))],
|
|
89
89
|
[0, q, t(q), e(q), n(e(q))],
|
|
90
|
-
[2,
|
|
90
|
+
[2, $, t($), e($), n(e($))],
|
|
91
91
|
[1, m, t(m), e(m), n(e(m))],
|
|
92
92
|
[2, T, t(T), e(T), n(e(T))],
|
|
93
93
|
[0, N, t(N), e(N), n(e(N))],
|
|
@@ -99,47 +99,47 @@ const he = 23.6, So = {
|
|
|
99
99
|
[2, Lt, t(Lt), e(Lt), n(e(Lt))],
|
|
100
100
|
[1, Bt, t(Bt), e(Bt), n(e(Bt))],
|
|
101
101
|
[0, Mt, t(Mt), e(Mt), n(e(Mt))],
|
|
102
|
-
[2,
|
|
103
|
-
[0,
|
|
104
|
-
[1,
|
|
105
|
-
[2,
|
|
102
|
+
[2, $t, t($t), e($t), n(e($t))],
|
|
103
|
+
[0, Tt, t(Tt), e(Tt), n(e(Tt))],
|
|
104
|
+
[1, Ft, t(Ft), e(Ft), n(e(Ft))],
|
|
105
|
+
[2, Rt, t(Rt), e(Rt), n(e(Rt))],
|
|
106
106
|
[0, De, t(De), e(De), n(e(De))],
|
|
107
107
|
[1, He, t(He), e(He), n(e(He))],
|
|
108
108
|
[2, Se, t(Se), e(Se), n(e(Se))],
|
|
109
109
|
[1, qe, t(qe), e(qe), n(e(qe))],
|
|
110
|
-
[0,
|
|
111
|
-
[2,
|
|
112
|
-
[1,
|
|
113
|
-
[0,
|
|
114
|
-
[1,
|
|
115
|
-
[2,
|
|
116
|
-
[0,
|
|
110
|
+
[0, yt, t(yt), e(yt), n(e(yt))],
|
|
111
|
+
[2, bt, t(bt), e(bt), n(e(bt))],
|
|
112
|
+
[1, xt, t(xt), e(xt), n(e(xt))],
|
|
113
|
+
[0, kt, t(kt), e(kt), n(e(kt))],
|
|
114
|
+
[1, Pt, t(Pt), e(Pt), n(e(Pt))],
|
|
115
|
+
[2, Ct, t(Ct), e(Ct), n(e(Ct))],
|
|
116
|
+
[0, Et, t(Et), e(Et), n(e(Et))],
|
|
117
117
|
[1, Ne, t(Ne), e(Ne), n(e(Ne))],
|
|
118
118
|
[2, ze, t(ze), e(ze), n(e(ze))],
|
|
119
|
-
[0,
|
|
119
|
+
[0, $e, t($e), e($e), n(e($e))],
|
|
120
120
|
[2, Te, t(Te), e(Te), n(e(Te))],
|
|
121
121
|
[1, vt, t(vt), e(vt), n(e(vt))],
|
|
122
122
|
[0, ht, t(ht), e(ht), n(e(ht))],
|
|
123
|
-
[2,
|
|
124
|
-
[1,
|
|
125
|
-
[2,
|
|
126
|
-
[0,
|
|
127
|
-
[1,
|
|
123
|
+
[2, dt, t(dt), e(dt), n(e(dt))],
|
|
124
|
+
[1, pt, t(pt), e(pt), n(e(pt))],
|
|
125
|
+
[2, mt, t(mt), e(mt), n(e(mt))],
|
|
126
|
+
[0, gt, t(gt), e(gt), n(e(gt))],
|
|
127
|
+
[1, wt, t(wt), e(wt), n(e(wt))],
|
|
128
128
|
[2, Fe, t(Fe), e(Fe), n(e(Fe))],
|
|
129
129
|
[0, Re, t(Re), e(Re), n(e(Re))],
|
|
130
130
|
[1, I, t(I), e(I), n(e(I))],
|
|
131
|
-
[0,
|
|
131
|
+
[0, J, t(J), e(J), n(e(J))],
|
|
132
132
|
[2, ke, t(ke), e(ke), n(e(ke))],
|
|
133
133
|
[1, Pe, t(Pe), e(Pe), n(e(Pe))],
|
|
134
134
|
[0, Ce, t(Ce), e(Ce), n(e(Ce))],
|
|
135
135
|
[2, Ee, t(Ee), e(Ee), n(e(Ee))],
|
|
136
|
-
[0,
|
|
137
|
-
[1,
|
|
138
|
-
[2,
|
|
139
|
-
[0,
|
|
140
|
-
[1,
|
|
141
|
-
[2,
|
|
142
|
-
[1,
|
|
136
|
+
[0, Le, t(Le), e(Le), n(e(Le))],
|
|
137
|
+
[1, Be, t(Be), e(Be), n(e(Be))],
|
|
138
|
+
[2, Me, t(Me), e(Me), n(e(Me))],
|
|
139
|
+
[0, _, t(_), e(_), n(e(_))],
|
|
140
|
+
[1, ee, t(ee), e(ee), n(e(ee))],
|
|
141
|
+
[2, U, t(U), e(U), n(e(U))],
|
|
142
|
+
[1, Z, t(Z), e(Z), n(e(Z))],
|
|
143
143
|
[0, pe, t(pe), e(pe), n(e(pe))],
|
|
144
144
|
[2, me, t(me), e(me), n(e(me))],
|
|
145
145
|
[1, ge, t(ge), e(ge), n(e(ge))],
|
|
@@ -147,42 +147,42 @@ const he = 23.6, So = {
|
|
|
147
147
|
[1, ye, t(ye), e(ye), n(e(ye))],
|
|
148
148
|
[2, be, t(be), e(be), n(e(be))],
|
|
149
149
|
[0, xe, t(xe), e(xe), n(e(xe))],
|
|
150
|
-
[1,
|
|
151
|
-
[2,
|
|
150
|
+
[1, j, t(j), e(j), n(e(j))],
|
|
151
|
+
[2, G, t(G), e(G), n(e(G))]
|
|
152
152
|
], No = [
|
|
153
|
-
["11", r(
|
|
154
|
-
["10", r(
|
|
155
|
-
["9", r(Ge, je,
|
|
156
|
-
["8", r(Ve, Qe,
|
|
157
|
-
["7", r(Xe, Oe,
|
|
158
|
-
["6", r(S, D,
|
|
159
|
-
["5", r(Ae, We,
|
|
160
|
-
["4", r(qe, Se,
|
|
161
|
-
["3", r(Te,
|
|
162
|
-
["2", r(
|
|
163
|
-
["1", r(
|
|
164
|
-
["a", r(I,
|
|
165
|
-
["b", r(
|
|
166
|
-
["c", r(ke, pe,
|
|
167
|
-
["d", r(Pe, me,
|
|
168
|
-
["e", r(Ce, ge,
|
|
169
|
-
["f", r(Ee, we,
|
|
170
|
-
["g", r(
|
|
171
|
-
["h", r(
|
|
172
|
-
["i", r(
|
|
173
|
-
["k", r(
|
|
174
|
-
["l", r(
|
|
175
|
-
["1", r(
|
|
176
|
-
["2", r(
|
|
177
|
-
["3", r(Fe, Re,
|
|
178
|
-
["4", r(Ne, ze,
|
|
179
|
-
["5", r(De, He,
|
|
180
|
-
["6", r(z, X,
|
|
181
|
-
["7", r(Ye, Ke,
|
|
182
|
-
["8", r(Ue, Ze,
|
|
183
|
-
["9", r(
|
|
184
|
-
["10", r(
|
|
185
|
-
["11", r(
|
|
153
|
+
["11", r(ne, le, u), t(r(ne, le, u))],
|
|
154
|
+
["10", r(oe, te, u), t(r(oe, te, u))],
|
|
155
|
+
["9", r(Ge, je, u), t(r(Ge, je, u))],
|
|
156
|
+
["8", r(Ve, Qe, u), t(r(Ve, Qe, u))],
|
|
157
|
+
["7", r(Xe, Oe, u), t(r(Xe, Oe, u))],
|
|
158
|
+
["6", r(S, D, u), t(r(S, D, u))],
|
|
159
|
+
["5", r(Ae, We, u), t(r(Ae, We, u))],
|
|
160
|
+
["4", r(qe, Se, u), t(r(qe, Se, u))],
|
|
161
|
+
["3", r(Te, $e, u), t(r(Te, $e, u))],
|
|
162
|
+
["2", r(J, I, u), t(r(J, I, u))],
|
|
163
|
+
["1", r(Z, U, u), t(r(Z, U, u))],
|
|
164
|
+
["a", r(I, U, u), t(r(I, U, u))],
|
|
165
|
+
["b", r(J, Z, u), t(r(J, Z, u))],
|
|
166
|
+
["c", r(ke, pe, u), t(r(ke, pe, u))],
|
|
167
|
+
["d", r(Pe, me, u), t(r(Pe, me, u))],
|
|
168
|
+
["e", r(Ce, ge, u), t(r(Ce, ge, u))],
|
|
169
|
+
["f", r(Ee, we, u), t(r(Ee, we, u))],
|
|
170
|
+
["g", r(Le, ye, u), t(r(Le, ye, u))],
|
|
171
|
+
["h", r(Be, be, u), t(r(Be, be, u))],
|
|
172
|
+
["i", r(Me, xe, u), t(r(Me, xe, u))],
|
|
173
|
+
["k", r(_, j, u), t(r(_, j, u))],
|
|
174
|
+
["l", r(ee, G, u), t(r(ee, G, u))],
|
|
175
|
+
["1", r(j, G, u), t(r(j, G, u))],
|
|
176
|
+
["2", r(_, ee, u), t(r(_, ee, u))],
|
|
177
|
+
["3", r(Fe, Re, u), t(r(Fe, Re, u))],
|
|
178
|
+
["4", r(Ne, ze, u), t(r(Ne, ze, u))],
|
|
179
|
+
["5", r(De, He, u), t(r(De, He, u))],
|
|
180
|
+
["6", r(z, X, u), t(r(z, X, u))],
|
|
181
|
+
["7", r(Ye, Ke, u), t(r(Ye, Ke, u))],
|
|
182
|
+
["8", r(Ue, Ze, u), t(r(Ue, Ze, u))],
|
|
183
|
+
["9", r(Ie, Je, u), t(r(Ie, Je, u))],
|
|
184
|
+
["10", r(oe, ne, u), t(r(oe, ne, u))],
|
|
185
|
+
["11", r(te, le, u), t(r(te, le, u))]
|
|
186
186
|
], zo = [
|
|
187
187
|
o[
|
|
188
188
|
0
|
|
@@ -557,17 +557,17 @@ const he = 23.6, So = {
|
|
|
557
557
|
/* e10 */
|
|
558
558
|
][3][0]
|
|
559
559
|
];
|
|
560
|
-
function
|
|
561
|
-
if (
|
|
560
|
+
function Xt(i) {
|
|
561
|
+
if (i.length === 0)
|
|
562
562
|
return "";
|
|
563
|
-
const [
|
|
564
|
-
let
|
|
565
|
-
for (const F of
|
|
566
|
-
|
|
567
|
-
return `${
|
|
563
|
+
const [B, ...v] = i;
|
|
564
|
+
let Q = `M ${R(ve(B[0]))} ${R(he(B[1]))} L `;
|
|
565
|
+
for (const F of v)
|
|
566
|
+
Q += `${R(ve(F[0]))} ${R(he(F[1]))} `;
|
|
567
|
+
return `${Q} Z`;
|
|
568
568
|
}
|
|
569
|
-
function R(
|
|
570
|
-
return
|
|
569
|
+
function R(i) {
|
|
570
|
+
return i.toFixed(8);
|
|
571
571
|
}
|
|
572
572
|
const Wo = {
|
|
573
573
|
viewBox: "0 0 50 50",
|
|
@@ -577,10 +577,10 @@ const Wo = {
|
|
|
577
577
|
props: {
|
|
578
578
|
type: {}
|
|
579
579
|
},
|
|
580
|
-
setup(
|
|
581
|
-
return (
|
|
580
|
+
setup(i) {
|
|
581
|
+
return (B, v) => (b(), P("svg", Wo, [
|
|
582
582
|
fo("text", {
|
|
583
|
-
textContent: vo(
|
|
583
|
+
textContent: vo(i.type),
|
|
584
584
|
"dominant-baseline": "middle",
|
|
585
585
|
"font-family": "sans-serif",
|
|
586
586
|
"font-size": "30",
|
|
@@ -590,11 +590,11 @@ const Wo = {
|
|
|
590
590
|
y: "27",
|
|
591
591
|
stroke: "oklch(37.3% 0.034 259.733)",
|
|
592
592
|
"stroke-width": "2",
|
|
593
|
-
fill:
|
|
593
|
+
fill: i.type === i.type.toLowerCase() ? "oklch(13% 0.028 261.692)" : "oklch(98.5% 0.002 247.839)"
|
|
594
594
|
}, null, 8, Ao)
|
|
595
595
|
]));
|
|
596
596
|
}
|
|
597
|
-
}), Ho = ["viewBox"], Oo = ["d", "fill"], Xo = ["d", "data-hexboard-position", "
|
|
597
|
+
}), Ho = ["viewBox"], Oo = ["d", "fill"], Xo = ["d", "data-hexboard-position", "fill"], Yo = ["d", "fill"], Ko = ["d", "fill"], Qo = ["textContent", "x", "y"], Vo = ["cx", "cy", "fill"], Uo = ["viewBox"], Go = /* @__PURE__ */ ao({
|
|
598
598
|
__name: "Hexboard",
|
|
599
599
|
props: /* @__PURE__ */ so({
|
|
600
600
|
active: { type: Boolean, default: !1 },
|
|
@@ -625,179 +625,179 @@ const Wo = {
|
|
|
625
625
|
targetsModifiers: {}
|
|
626
626
|
}),
|
|
627
627
|
emits: /* @__PURE__ */ so(["clickPosition", "move"], ["update:mouseover-position", "update:selected", "update:targets"]),
|
|
628
|
-
setup(
|
|
629
|
-
const
|
|
628
|
+
setup(i, { emit: B }) {
|
|
629
|
+
const v = i, Q = B, F = Zt(i, "mouseover-position"), C = Zt(i, "selected"), W = Zt(i, "targets"), _e = tt({ x: 0, y: 0 }), M = tt(null), ie = tt(se()), d = tt({
|
|
630
630
|
hexchess: null,
|
|
631
631
|
promotionEl: null,
|
|
632
632
|
promotionFrom: null,
|
|
633
633
|
promotionTo: null,
|
|
634
634
|
selected: null
|
|
635
|
-
}),
|
|
636
|
-
let
|
|
637
|
-
const ho =
|
|
638
|
-
(s, f,
|
|
635
|
+
}), Yt = Co("svgEl"), Y = tt(se());
|
|
636
|
+
let Kt = !1;
|
|
637
|
+
const ho = A(() => d.value.hexchess ? [] : W.value), ce = A(() => d.value.hexchess ? d.value.hexchess : v.hexchess ? v.hexchess : co.init()), po = A(() => ce.value.board.reduce(
|
|
638
|
+
(s, f, c) => (f && c !== M.value && s.push({ piece: f, index: c }), s),
|
|
639
639
|
[]
|
|
640
|
-
)),
|
|
641
|
-
var s, f,
|
|
640
|
+
)), Qt = A(() => typeof d.value.selected == "number" ? null : C.value), jt = A(() => {
|
|
641
|
+
var s, f, c;
|
|
642
642
|
if (Vt.value)
|
|
643
643
|
return "grabbing";
|
|
644
|
-
if (!(!
|
|
645
|
-
if (
|
|
646
|
-
const
|
|
647
|
-
if (
|
|
648
|
-
const g =
|
|
649
|
-
if ((
|
|
644
|
+
if (!(!v.active || F.value === null || d.value.hexchess)) {
|
|
645
|
+
if (C.value !== null && W.value.includes(F.value)) {
|
|
646
|
+
const h = (s = ce.value) == null ? void 0 : s.board[C.value];
|
|
647
|
+
if (h) {
|
|
648
|
+
const g = h === h.toLowerCase() ? "b" : "w", E = ((f = ce.value) == null ? void 0 : f.turn) === g;
|
|
649
|
+
if ((v.playing === !0 || E) && ut(C.value))
|
|
650
650
|
return "pointer";
|
|
651
651
|
}
|
|
652
652
|
}
|
|
653
|
-
if (
|
|
654
|
-
return
|
|
653
|
+
if (st.value)
|
|
654
|
+
return v.playing === !0 || v.playing && It.value === ((c = ce.value) == null ? void 0 : c.turn) && v.playing === It.value ? "grab" : "pointer";
|
|
655
655
|
}
|
|
656
|
-
}), Gt =
|
|
657
|
-
x: _e.value.x -
|
|
658
|
-
y: _e.value.y -
|
|
659
|
-
})), Vt =
|
|
656
|
+
}), Gt = A(() => ({
|
|
657
|
+
x: _e.value.x - Y.value.width / 2,
|
|
658
|
+
y: _e.value.y - Y.value.height / 2
|
|
659
|
+
})), Vt = A(() => !v.hexchess || d.value.hexchess || M.value === null ? null : v.hexchess.board[M.value]), K = A(() => ({ ...So, ...v.options })), It = A(() => st.value ? st.value === st.value.toLowerCase() ? "b" : "w" : null), st = A(() => {
|
|
660
660
|
var s;
|
|
661
|
-
return F.value === null ? null : ((s =
|
|
662
|
-
}),
|
|
663
|
-
var
|
|
664
|
-
const s = (
|
|
661
|
+
return F.value === null ? null : ((s = ce.value) == null ? void 0 : s.board[F.value]) ?? null;
|
|
662
|
+
}), rt = A(() => {
|
|
663
|
+
var h;
|
|
664
|
+
const s = (h = d.value.hexchess) == null ? void 0 : h.board[d.value.selected ?? -1], f = s === (s == null ? void 0 : s.toUpperCase()), c = (g) => (E) => To(v.pieces, { ...E, type: g });
|
|
665
665
|
return {
|
|
666
|
-
n:
|
|
667
|
-
b:
|
|
668
|
-
r:
|
|
669
|
-
q:
|
|
666
|
+
n: c(f ? "N" : "n"),
|
|
667
|
+
b: c(f ? "B" : "b"),
|
|
668
|
+
r: c(f ? "R" : "r"),
|
|
669
|
+
q: c(f ? "Q" : "q")
|
|
670
670
|
};
|
|
671
671
|
});
|
|
672
672
|
Eo(() => {
|
|
673
|
-
|
|
674
|
-
}),
|
|
673
|
+
v.active && Jt();
|
|
674
|
+
}), Lo(lo), ro(jt, (s) => {
|
|
675
675
|
document.body.style.setProperty(
|
|
676
676
|
"cursor",
|
|
677
677
|
s === "grabbing" ? "grabbing" : null
|
|
678
678
|
);
|
|
679
679
|
}), ro(
|
|
680
|
-
() =>
|
|
681
|
-
(s) => s ?
|
|
680
|
+
() => v.active,
|
|
681
|
+
(s) => s ? Jt() : lo()
|
|
682
682
|
);
|
|
683
683
|
function Ut(s, f) {
|
|
684
|
-
var
|
|
685
|
-
if (!
|
|
684
|
+
var E, re;
|
|
685
|
+
if (!W.value.includes(s.to))
|
|
686
686
|
return;
|
|
687
|
-
const
|
|
688
|
-
if (!
|
|
687
|
+
const c = (E = v.hexchess) == null ? void 0 : E.board[s.from];
|
|
688
|
+
if (!c)
|
|
689
689
|
return;
|
|
690
|
-
const
|
|
691
|
-
if (
|
|
692
|
-
const
|
|
693
|
-
|
|
694
|
-
hexchess:
|
|
690
|
+
const h = c === c.toLowerCase() ? "b" : "w", g = ((re = v.hexchess) == null ? void 0 : re.turn) === h;
|
|
691
|
+
if (v.hexchess && (c === "p" || c === "P") && Fo(s.to, h)) {
|
|
692
|
+
const ae = v.hexchess.clone();
|
|
693
|
+
ae.board[s.from] = null, ae.board[s.to] = c, d.value = {
|
|
694
|
+
hexchess: ae,
|
|
695
695
|
promotionEl: (f == null ? void 0 : f.target) instanceof Element ? f.target : null,
|
|
696
696
|
promotionFrom: s.from,
|
|
697
697
|
promotionTo: s.to,
|
|
698
698
|
selected: s.to
|
|
699
|
-
}, (f == null ? void 0 : f.target) instanceof Element && (
|
|
699
|
+
}, (f == null ? void 0 : f.target) instanceof Element && (ie.value = f.target.getBoundingClientRect());
|
|
700
700
|
return;
|
|
701
701
|
}
|
|
702
|
-
ut(s.from) && (
|
|
702
|
+
ut(s.from) && (v.ignoreTurn || g) && eo(s);
|
|
703
703
|
}
|
|
704
704
|
function ut(s) {
|
|
705
|
-
var
|
|
706
|
-
const f = (
|
|
705
|
+
var h;
|
|
706
|
+
const f = (h = v.hexchess) == null ? void 0 : h.board[s];
|
|
707
707
|
if (!f)
|
|
708
708
|
return !1;
|
|
709
|
-
const
|
|
710
|
-
return
|
|
709
|
+
const c = f === f.toLowerCase() ? "b" : "w";
|
|
710
|
+
return v.playing === !0 || v.playing === c;
|
|
711
711
|
}
|
|
712
712
|
function mo(s) {
|
|
713
|
-
var f,
|
|
714
|
-
return F.value === null ?
|
|
713
|
+
var f, c;
|
|
714
|
+
return F.value === null ? K.value.labelColor : (f = fe(F.value)) != null && f.startsWith(s) || (c = fe(F.value)) != null && c.endsWith(s) ? K.value.labelActiveColor : K.value.labelInactiveColor;
|
|
715
715
|
}
|
|
716
|
-
function
|
|
717
|
-
_e.value = { x: 0, y: 0 }, window.addEventListener("keyup", _t), window.addEventListener("pointermove", to), window.addEventListener("pointerup", no), window.addEventListener("resize",
|
|
716
|
+
function Jt() {
|
|
717
|
+
_e.value = { x: 0, y: 0 }, window.addEventListener("keyup", _t), window.addEventListener("pointermove", to), window.addEventListener("pointerup", no), window.addEventListener("resize", it), window.addEventListener("scroll", it), window.addEventListener("touchmove", oo, { passive: !1 });
|
|
718
718
|
}
|
|
719
|
-
function
|
|
719
|
+
function it() {
|
|
720
720
|
var s;
|
|
721
|
-
|
|
721
|
+
ie.value = ((s = d.value.promotionEl) == null ? void 0 : s.getBoundingClientRect()) ?? se();
|
|
722
722
|
}
|
|
723
723
|
function go(s, f) {
|
|
724
|
-
if (
|
|
725
|
-
if (
|
|
726
|
-
|
|
724
|
+
if (v.active) {
|
|
725
|
+
if (Kt) {
|
|
726
|
+
Kt = !1;
|
|
727
727
|
return;
|
|
728
728
|
}
|
|
729
|
-
if (
|
|
730
|
-
|
|
729
|
+
if (d.value.hexchess) {
|
|
730
|
+
d.value.selected !== s && et();
|
|
731
731
|
return;
|
|
732
732
|
}
|
|
733
|
-
if (
|
|
734
|
-
const
|
|
735
|
-
Ut(
|
|
733
|
+
if (C.value !== null && W.value.includes(s)) {
|
|
734
|
+
const c = new ft({ from: C.value, to: s });
|
|
735
|
+
Ut(c, f);
|
|
736
736
|
return;
|
|
737
737
|
}
|
|
738
|
-
|
|
738
|
+
v.autoselect && !v.hexchess.board[s] && (C.value = null, W.value = []), Q("clickPosition", s);
|
|
739
739
|
}
|
|
740
740
|
}
|
|
741
741
|
function _t(s) {
|
|
742
742
|
if (s.key === "Escape") {
|
|
743
|
-
if (
|
|
743
|
+
if (d.value.hexchess) {
|
|
744
744
|
et();
|
|
745
745
|
return;
|
|
746
746
|
}
|
|
747
|
-
|
|
747
|
+
v.autoselect && (C.value = null, W.value = []);
|
|
748
748
|
}
|
|
749
749
|
}
|
|
750
750
|
function eo(s) {
|
|
751
|
-
|
|
751
|
+
Q("move", s), ct();
|
|
752
752
|
}
|
|
753
753
|
function wo(s, f) {
|
|
754
|
-
var
|
|
755
|
-
if (f.stopPropagation(),
|
|
756
|
-
let
|
|
754
|
+
var c;
|
|
755
|
+
if (f.stopPropagation(), M.value !== null) {
|
|
756
|
+
let h = s;
|
|
757
757
|
const g = document.elementFromPoint(
|
|
758
758
|
f.clientX,
|
|
759
759
|
f.clientY
|
|
760
|
-
),
|
|
761
|
-
|
|
762
|
-
const
|
|
763
|
-
if (Ut(
|
|
760
|
+
), E = g == null ? void 0 : g.getAttribute("data-hexboard-position");
|
|
761
|
+
E !== null && (h = Number(E));
|
|
762
|
+
const re = new ft({ from: M.value, to: h });
|
|
763
|
+
if (Ut(re, f), d.value.hexchess)
|
|
764
764
|
return;
|
|
765
|
-
|
|
765
|
+
M.value = null, Y.value = se();
|
|
766
766
|
return;
|
|
767
767
|
}
|
|
768
|
-
if (
|
|
769
|
-
const
|
|
770
|
-
return Ut(
|
|
768
|
+
if (C.value !== null && W.value.includes(s)) {
|
|
769
|
+
const h = new ft({ from: C.value, to: s });
|
|
770
|
+
return Ut(h, f), d.value.hexchess, void 0;
|
|
771
771
|
}
|
|
772
|
-
if (
|
|
772
|
+
if (d.value.hexchess) {
|
|
773
773
|
et();
|
|
774
774
|
return;
|
|
775
775
|
}
|
|
776
|
-
if ((
|
|
777
|
-
|
|
776
|
+
if ((c = v.hexchess) != null && c.board[s]) {
|
|
777
|
+
M.value = null, Y.value = se();
|
|
778
778
|
return;
|
|
779
779
|
}
|
|
780
|
-
|
|
780
|
+
ct();
|
|
781
781
|
}
|
|
782
782
|
function et() {
|
|
783
|
-
const s =
|
|
784
|
-
|
|
783
|
+
const s = d.value.promotionFrom;
|
|
784
|
+
d.value = {
|
|
785
785
|
hexchess: null,
|
|
786
786
|
promotionEl: null,
|
|
787
787
|
promotionFrom: null,
|
|
788
788
|
promotionTo: null,
|
|
789
789
|
selected: null
|
|
790
|
-
}, typeof s == "number" && (
|
|
790
|
+
}, typeof s == "number" && (C.value = s, W.value = v.hexchess.movesFrom(s).map((f) => f.to) ?? []), M.value = null, Kt = !0;
|
|
791
791
|
}
|
|
792
792
|
function yo(s, f) {
|
|
793
|
-
var
|
|
794
|
-
if (f.preventDefault(),
|
|
793
|
+
var E, re, ae;
|
|
794
|
+
if (f.preventDefault(), d.value.hexchess || C.value !== null && W.value.includes(s))
|
|
795
795
|
return;
|
|
796
|
-
const
|
|
797
|
-
if (!
|
|
796
|
+
const c = (E = v.hexchess) == null ? void 0 : E.board[s];
|
|
797
|
+
if (!c || (v.autoselect && (C.value = s, W.value = ((re = v.hexchess) == null ? void 0 : re.movesFrom(s).map((Po) => Po.to)) ?? []), !ut(s)))
|
|
798
798
|
return;
|
|
799
|
-
const
|
|
800
|
-
!
|
|
799
|
+
const h = c === c.toLowerCase() ? "b" : "w", g = ((ae = v.hexchess) == null ? void 0 : ae.turn) === h;
|
|
800
|
+
!v.ignoreTurn && !g || (M.value = s, _e.value = { x: f.clientX, y: f.clientY }, Yt.value instanceof Element && (Y.value = Yt.value.getBoundingClientRect()));
|
|
801
801
|
}
|
|
802
802
|
function bo(s) {
|
|
803
803
|
F.value = s;
|
|
@@ -806,33 +806,33 @@ const Wo = {
|
|
|
806
806
|
F.value = null;
|
|
807
807
|
}
|
|
808
808
|
function to(s) {
|
|
809
|
-
|
|
809
|
+
v.active && (_e.value = { x: s.clientX, y: s.clientY });
|
|
810
810
|
}
|
|
811
811
|
function oo(s) {
|
|
812
|
-
|
|
812
|
+
M.value !== null && s.preventDefault();
|
|
813
813
|
}
|
|
814
814
|
function no() {
|
|
815
|
-
if (
|
|
815
|
+
if (d.value.hexchess) {
|
|
816
816
|
et();
|
|
817
817
|
return;
|
|
818
818
|
}
|
|
819
|
-
if (
|
|
820
|
-
|
|
819
|
+
if (M.value !== null) {
|
|
820
|
+
M.value = null, Y.value = se();
|
|
821
821
|
return;
|
|
822
822
|
}
|
|
823
|
-
|
|
823
|
+
ct();
|
|
824
824
|
}
|
|
825
825
|
function ko(s) {
|
|
826
|
-
if (typeof
|
|
827
|
-
const f = new
|
|
828
|
-
from:
|
|
829
|
-
to:
|
|
826
|
+
if (typeof d.value.promotionFrom == "number" && ut(d.value.promotionFrom)) {
|
|
827
|
+
const f = new ft({
|
|
828
|
+
from: d.value.promotionFrom ?? 0,
|
|
829
|
+
to: d.value.promotionTo ?? 0,
|
|
830
830
|
promotion: s
|
|
831
831
|
});
|
|
832
832
|
eo(f);
|
|
833
833
|
}
|
|
834
834
|
}
|
|
835
|
-
function
|
|
835
|
+
function se() {
|
|
836
836
|
return {
|
|
837
837
|
bottom: 0,
|
|
838
838
|
height: 0,
|
|
@@ -844,145 +844,138 @@ const Wo = {
|
|
|
844
844
|
y: 0
|
|
845
845
|
};
|
|
846
846
|
}
|
|
847
|
-
function
|
|
848
|
-
document.body.style.setProperty("cursor", null),
|
|
847
|
+
function ct() {
|
|
848
|
+
document.body.style.setProperty("cursor", null), M.value = null, C.value = null, d.value = {
|
|
849
849
|
hexchess: null,
|
|
850
850
|
promotionEl: null,
|
|
851
851
|
promotionFrom: null,
|
|
852
852
|
promotionTo: null,
|
|
853
853
|
selected: null
|
|
854
|
-
},
|
|
854
|
+
}, Y.value = se(), W.value = [];
|
|
855
855
|
}
|
|
856
856
|
function lo() {
|
|
857
|
-
|
|
857
|
+
ct(), window.removeEventListener("keyup", _t), window.removeEventListener("pointermove", to), window.removeEventListener("pointerup", no), window.removeEventListener("resize", it), window.removeEventListener("scroll", it), window.removeEventListener("touchmove", oo);
|
|
858
858
|
}
|
|
859
859
|
return (s, f) => (b(), P("div", null, [
|
|
860
860
|
(b(), P("svg", {
|
|
861
861
|
xmlns: "http://www.w3.org/2000/svg",
|
|
862
862
|
ref_key: "svgEl",
|
|
863
|
-
ref:
|
|
864
|
-
style:
|
|
865
|
-
viewBox: `0 0 ${
|
|
863
|
+
ref: Yt,
|
|
864
|
+
style: at({ cursor: jt.value }),
|
|
865
|
+
viewBox: `0 0 ${a(de)} ${a(de)}`
|
|
866
866
|
}, [
|
|
867
867
|
fo("path", {
|
|
868
|
-
d:
|
|
869
|
-
fill:
|
|
868
|
+
d: a(Xt)(a(zo)),
|
|
869
|
+
fill: K.value.colors[1],
|
|
870
870
|
style: { pointerEvents: "none" }
|
|
871
871
|
}, null, 8, Oo),
|
|
872
|
-
(b(!0), P(nt, null, lt(
|
|
872
|
+
(b(!0), P(nt, null, lt(a(o), (c, h) => (b(), P("path", Bo(
|
|
873
873
|
{ ref_for: !0 },
|
|
874
|
-
|
|
875
|
-
onClick: (g) => go(
|
|
876
|
-
onMouseenter: () => bo(
|
|
874
|
+
i.active ? {
|
|
875
|
+
onClick: (g) => go(h, g),
|
|
876
|
+
onMouseenter: () => bo(h),
|
|
877
877
|
onMouseleave: () => xo(),
|
|
878
|
-
onPointerdown: (g) => yo(
|
|
879
|
-
onPointerup: (g) => wo(
|
|
878
|
+
onPointerdown: (g) => yo(h, g),
|
|
879
|
+
onPointerup: (g) => wo(h, g)
|
|
880
880
|
} : {},
|
|
881
881
|
{
|
|
882
|
-
d:
|
|
883
|
-
"data-hexboard-position":
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
key: v
|
|
882
|
+
d: a(Xt)(i.flipped ? c[4] : c[3]),
|
|
883
|
+
"data-hexboard-position": h,
|
|
884
|
+
fill: K.value.colors[a(o)[h][0]],
|
|
885
|
+
key: h
|
|
887
886
|
}
|
|
888
887
|
), null, 16, Xo))), 128)),
|
|
889
|
-
(b(!0), P(nt, null, lt(
|
|
890
|
-
d:
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
key: `highlight-${a}`,
|
|
888
|
+
(b(!0), P(nt, null, lt(i.highlight, (c) => (b(), P("path", {
|
|
889
|
+
d: a(Xt)(i.flipped ? a(o)[c][4] : a(o)[c][3]),
|
|
890
|
+
fill: K.value.highlightColor,
|
|
891
|
+
key: `highlight-${c}`,
|
|
894
892
|
style: { pointerEvents: "none" }
|
|
895
893
|
}, null, 8, Yo))), 128)),
|
|
896
|
-
typeof
|
|
894
|
+
typeof Qt.value == "number" ? (b(), P("path", {
|
|
897
895
|
key: 0,
|
|
898
|
-
d:
|
|
899
|
-
|
|
900
|
-
fill: Q.value.selectedColor,
|
|
896
|
+
d: a(Xt)(i.flipped ? a(o)[Qt.value][4] : a(o)[Qt.value][3]),
|
|
897
|
+
fill: K.value.selectedColor,
|
|
901
898
|
ref: "selectedEl",
|
|
902
899
|
style: { pointerEvents: "none" }
|
|
903
900
|
}, null, 8, Ko)) : ot("", !0),
|
|
904
|
-
|
|
905
|
-
textContent: vo(
|
|
901
|
+
K.value.labels ? (b(!0), P(nt, { key: 1 }, lt(a(No), ([c, h, g], E) => (b(), P("text", {
|
|
902
|
+
textContent: vo(c),
|
|
906
903
|
"dominant-baseline": "central",
|
|
907
904
|
"text-anchor": "middle",
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
fill: mo(a),
|
|
905
|
+
key: `label-${E}`,
|
|
906
|
+
style: at({
|
|
907
|
+
fill: mo(c),
|
|
912
908
|
fontSize: ".5px",
|
|
913
909
|
pointerEvents: "none",
|
|
914
910
|
userSelect: "none"
|
|
915
911
|
}),
|
|
916
|
-
x:
|
|
917
|
-
y:
|
|
912
|
+
x: a(R)(a(ve)(i.flipped ? g[0] : h[0])),
|
|
913
|
+
y: a(R)(a(he)(i.flipped ? g[1] : h[1]))
|
|
918
914
|
}, null, 12, Qo))), 128)) : ot("", !0),
|
|
919
|
-
|
|
920
|
-
"data-piece-type":
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
key: `piece-${c(A)(v)}`,
|
|
915
|
+
ce.value ? (b(!0), P(nt, { key: 2 }, lt(po.value, ({ piece: c, index: h }) => (b(), uo(io(i.pieces), {
|
|
916
|
+
"data-piece-type": c,
|
|
917
|
+
height: a(V),
|
|
918
|
+
key: `piece-${a(fe)(h)}`,
|
|
924
919
|
style: { pointerEvents: "none" },
|
|
925
|
-
type:
|
|
926
|
-
width:
|
|
927
|
-
x:
|
|
928
|
-
y:
|
|
929
|
-
}, null, 8, ["data-piece-type", "
|
|
930
|
-
(b(!0), P(nt, null, lt(ho.value, (
|
|
931
|
-
cx:
|
|
932
|
-
cy:
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
key: `target-${c(A)(a)}`,
|
|
920
|
+
type: c,
|
|
921
|
+
width: a(V),
|
|
922
|
+
x: a(R)(a(ve)(a(o)[h][i.flipped ? 2 : 1][0] - a(V) / 2)),
|
|
923
|
+
y: a(R)(a(he)(a(o)[h][i.flipped ? 2 : 1][1] + a(V) / 2))
|
|
924
|
+
}, null, 8, ["data-piece-type", "height", "type", "width", "x", "y"]))), 128)) : ot("", !0),
|
|
925
|
+
(b(!0), P(nt, null, lt(ho.value, (c) => (b(), P("circle", {
|
|
926
|
+
cx: a(R)(a(ve)(a(o)[c][i.flipped ? 2 : 1][0])),
|
|
927
|
+
cy: a(R)(a(he)(a(o)[c][i.flipped ? 2 : 1][1])),
|
|
928
|
+
fill: K.value.targetColor,
|
|
929
|
+
key: `target-${a(fe)(c)}`,
|
|
936
930
|
r: 0.3,
|
|
937
931
|
style: { pointerEvents: "none" }
|
|
938
932
|
}, null, 8, Vo))), 128))
|
|
939
933
|
], 12, Ho)),
|
|
940
934
|
Vt.value ? (b(), P("svg", {
|
|
941
935
|
key: 0,
|
|
942
|
-
"data-testid": "drag-piece",
|
|
943
936
|
xmlns: "http://www.w3.org/2000/svg",
|
|
944
|
-
style:
|
|
945
|
-
height:
|
|
937
|
+
style: at({
|
|
938
|
+
height: Y.value.height + "px",
|
|
946
939
|
left: "0px",
|
|
947
940
|
pointerEvents: "none",
|
|
948
941
|
position: "fixed",
|
|
949
942
|
top: "0px",
|
|
950
943
|
transform: `translate(${Gt.value.x}px, ${Gt.value.y}px) scale(1.1)`,
|
|
951
|
-
width:
|
|
944
|
+
width: Y.value.width + "px",
|
|
952
945
|
willChange: "transform"
|
|
953
946
|
}),
|
|
954
|
-
viewBox: `0 0 ${
|
|
947
|
+
viewBox: `0 0 ${a(de)} ${a(de)}`
|
|
955
948
|
}, [
|
|
956
|
-
(b(), io(
|
|
957
|
-
height:
|
|
949
|
+
(b(), uo(io(i.pieces), {
|
|
950
|
+
height: a(V),
|
|
958
951
|
style: { pointerEvents: "none" },
|
|
959
952
|
type: Vt.value,
|
|
960
|
-
width:
|
|
961
|
-
x:
|
|
962
|
-
y:
|
|
953
|
+
width: a(V),
|
|
954
|
+
x: a(R)(a(ve)(a(V) / -2)),
|
|
955
|
+
y: a(R)(a(he)(a(V) / 2))
|
|
963
956
|
}, null, 8, ["height", "type", "width", "x", "y"]))
|
|
964
957
|
], 12, Uo)) : ot("", !0),
|
|
965
|
-
typeof
|
|
958
|
+
typeof d.value.selected == "number" ? (b(), P("div", {
|
|
966
959
|
key: 1,
|
|
967
|
-
style:
|
|
968
|
-
height:
|
|
969
|
-
left:
|
|
960
|
+
style: at({
|
|
961
|
+
height: ie.value.height + "px",
|
|
962
|
+
left: ie.value.left + "px",
|
|
970
963
|
position: "fixed",
|
|
971
|
-
top:
|
|
972
|
-
width:
|
|
964
|
+
top: ie.value.top + "px",
|
|
965
|
+
width: ie.value.width + "px"
|
|
973
966
|
}),
|
|
974
|
-
onPointerup: f[0] || (f[0] =
|
|
967
|
+
onPointerup: f[0] || (f[0] = Mo(() => {
|
|
975
968
|
}, ["stop"]))
|
|
976
969
|
}, [
|
|
977
|
-
|
|
978
|
-
b:
|
|
970
|
+
$o(s.$slots, "promotion", {
|
|
971
|
+
b: rt.value.b,
|
|
979
972
|
cancel: et,
|
|
980
|
-
file:
|
|
981
|
-
n:
|
|
973
|
+
file: a(fe)(d.value.selected)[0],
|
|
974
|
+
n: rt.value.n,
|
|
982
975
|
promote: ko,
|
|
983
|
-
q:
|
|
984
|
-
r:
|
|
985
|
-
rank: Number(
|
|
976
|
+
q: rt.value.q,
|
|
977
|
+
r: rt.value.r,
|
|
978
|
+
rank: Number(a(fe)(d.value.selected).slice(1))
|
|
986
979
|
})
|
|
987
980
|
], 36)) : ot("", !0)
|
|
988
981
|
]));
|
package/package.json
CHANGED
|
@@ -738,6 +738,12 @@ function onPointerdownPosition(index: number, evt: PointerEvent) {
|
|
|
738
738
|
return
|
|
739
739
|
}
|
|
740
740
|
|
|
741
|
+
// If clicking on a valid target for the selected piece, don't re-select
|
|
742
|
+
// (the move will be handled in onPointerupPosition/onClickPosition)
|
|
743
|
+
if (selected.value !== null && targets.value.includes(index)) {
|
|
744
|
+
return
|
|
745
|
+
}
|
|
746
|
+
|
|
741
747
|
const piece = props.hexchess?.board[index]
|
|
742
748
|
|
|
743
749
|
if (!piece) {
|
|
@@ -3,7 +3,7 @@ import { expect, test, vi } from 'vitest'
|
|
|
3
3
|
import { Hexboard } from '../lib'
|
|
4
4
|
import { Hexchess } from '@bedard/hexchess'
|
|
5
5
|
import { index, San } from '@bedard/hexchess'
|
|
6
|
-
import {
|
|
6
|
+
import { dragMove, clickMove, setup } from './utils'
|
|
7
7
|
import { page } from 'vitest/browser'
|
|
8
8
|
import { ref, nextTick } from 'vue'
|
|
9
9
|
import { userEvent } from 'vitest/browser'
|
|
@@ -520,23 +520,7 @@ test('drag and drop piece emits move event', async () => {
|
|
|
520
520
|
)
|
|
521
521
|
})
|
|
522
522
|
|
|
523
|
-
|
|
524
|
-
const toPosition = page.getByTestId('position-f6')
|
|
525
|
-
|
|
526
|
-
// Start dragging the piece (pointerdown)
|
|
527
|
-
await fromPosition
|
|
528
|
-
.element()
|
|
529
|
-
.dispatchEvent(new PointerEvent('pointerdown', { bubbles: true }))
|
|
530
|
-
await nextTick()
|
|
531
|
-
|
|
532
|
-
// Verify dragging started
|
|
533
|
-
await expect.element(page.getByTestId('drag-piece')).toBeVisible()
|
|
534
|
-
|
|
535
|
-
// Move pointer to target position and release (pointerup)
|
|
536
|
-
await toPosition
|
|
537
|
-
.element()
|
|
538
|
-
.dispatchEvent(new PointerEvent('pointerup', { bubbles: true }))
|
|
539
|
-
await nextTick()
|
|
523
|
+
await dragMove(page, 'f5f6')
|
|
540
524
|
|
|
541
525
|
// Verify move event was emitted with correct San object
|
|
542
526
|
await expect(onMove).toHaveBeenCalledOnce()
|
|
@@ -644,7 +628,7 @@ test('promotion', async () => {
|
|
|
644
628
|
)
|
|
645
629
|
})
|
|
646
630
|
|
|
647
|
-
await
|
|
631
|
+
await clickMove(page, 'f10f11')
|
|
648
632
|
await page.getByTestId('promote').click()
|
|
649
633
|
await expect(page.getByTestId('piece-f11')).toHaveAttribute(
|
|
650
634
|
'data-piece-type',
|
|
@@ -682,7 +666,7 @@ test('canceled promotion', async () => {
|
|
|
682
666
|
})
|
|
683
667
|
|
|
684
668
|
// Move pawn to promotion square
|
|
685
|
-
await
|
|
669
|
+
await clickMove(page, 'f10f11')
|
|
686
670
|
|
|
687
671
|
// Promotion UI should be visible
|
|
688
672
|
await expect.element(page.getByTestId('cancel')).toBeVisible()
|
|
@@ -730,7 +714,7 @@ test('clicking position during promotion cancels it', async () => {
|
|
|
730
714
|
})
|
|
731
715
|
|
|
732
716
|
// Move pawn to promotion square
|
|
733
|
-
await
|
|
717
|
+
await clickMove(page, 'f10f11')
|
|
734
718
|
|
|
735
719
|
// Promotion UI should be visible
|
|
736
720
|
await expect.element(page.getByTestId('promote')).toBeVisible()
|
|
@@ -771,14 +755,14 @@ test('ignoreTurn allows moving pieces out of turn', async () => {
|
|
|
771
755
|
})
|
|
772
756
|
|
|
773
757
|
// Initial position is white's turn, try to move black's pawn without ignoreTurn
|
|
774
|
-
await
|
|
758
|
+
await clickMove(page, 'f7f6')
|
|
775
759
|
await expect(onMove).not.toHaveBeenCalled()
|
|
776
760
|
|
|
777
761
|
// Enable ignoreTurn and try again
|
|
778
762
|
ignoreTurn.value = true
|
|
779
763
|
await nextTick()
|
|
780
764
|
|
|
781
|
-
await
|
|
765
|
+
await clickMove(page, 'f7f6')
|
|
782
766
|
await expect(onMove).toHaveBeenCalledOnce()
|
|
783
767
|
await expect(onMove).toHaveBeenCalledWith(
|
|
784
768
|
expect.objectContaining({
|
|
@@ -791,6 +775,7 @@ test('ignoreTurn allows moving pieces out of turn', async () => {
|
|
|
791
775
|
test('dragging piece to non-target position keeps selection', async () => {
|
|
792
776
|
const selected = ref<number | null>(null)
|
|
793
777
|
const targets = ref<number[]>([])
|
|
778
|
+
const onMove = vi.fn()
|
|
794
779
|
|
|
795
780
|
setup(() => {
|
|
796
781
|
return () => (
|
|
@@ -801,32 +786,63 @@ test('dragging piece to non-target position keeps selection', async () => {
|
|
|
801
786
|
playing="w"
|
|
802
787
|
v-model:selected={selected.value}
|
|
803
788
|
v-model:targets={targets.value}
|
|
789
|
+
onMove={onMove}
|
|
804
790
|
/>
|
|
805
791
|
<div data-testid="selected-value" v-text={selected.value} />
|
|
806
792
|
</>
|
|
807
793
|
)
|
|
808
794
|
})
|
|
809
795
|
|
|
810
|
-
|
|
811
|
-
const nonTargetPosition = page.getByTestId('position-a1')
|
|
812
|
-
|
|
813
|
-
// Start dragging the piece
|
|
814
|
-
await piecePosition
|
|
815
|
-
.element()
|
|
816
|
-
.dispatchEvent(new PointerEvent('pointerdown', { bubbles: true }))
|
|
817
|
-
await nextTick()
|
|
796
|
+
await dragMove(page, 'f5a1')
|
|
818
797
|
|
|
819
|
-
//
|
|
798
|
+
// Piece should still be selected
|
|
820
799
|
await expect.element(page.getByTestId('selected-f5')).toBeVisible()
|
|
821
800
|
await expect(selected.value).toBe(index('f5'))
|
|
822
801
|
|
|
823
|
-
//
|
|
824
|
-
await
|
|
825
|
-
|
|
826
|
-
.dispatchEvent(new PointerEvent('pointerup', { bubbles: true }))
|
|
827
|
-
await nextTick()
|
|
802
|
+
// No move should have been emitted
|
|
803
|
+
await expect(onMove).not.toHaveBeenCalled()
|
|
804
|
+
})
|
|
828
805
|
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
806
|
+
test('click capture', async () => {
|
|
807
|
+
const hexchess = ref(
|
|
808
|
+
Hexchess.parse('b/qbk/n1b1n/r5r/ppp1ppppp/11/4pP5/4P1P4/3P1B1P3/2P2B2P2/1PRNQBKNRP1 w e6 0 2'),
|
|
809
|
+
)
|
|
810
|
+
|
|
811
|
+
setup(() => {
|
|
812
|
+
return () => (
|
|
813
|
+
<Hexboard
|
|
814
|
+
active
|
|
815
|
+
autoselect
|
|
816
|
+
playing={true}
|
|
817
|
+
hexchess={hexchess.value}
|
|
818
|
+
onMove={san => hexchess.value.applyMoveUnsafe(san)}
|
|
819
|
+
/>
|
|
820
|
+
)
|
|
821
|
+
})
|
|
822
|
+
|
|
823
|
+
await clickMove(page, 'f5e5')
|
|
824
|
+
|
|
825
|
+
await expect(hexchess.value.toString()).toBe('b/qbk/n1b1n/r5r/ppp1ppppp/11/4P6/4P1P4/3P1B1P3/2P2B2P2/1PRNQBKNRP1 b - 0 2')
|
|
826
|
+
})
|
|
827
|
+
|
|
828
|
+
test('drag capture', async () => {
|
|
829
|
+
const hexchess = ref(
|
|
830
|
+
Hexchess.parse('b/qbk/n1b1n/r5r/ppp1ppppp/11/4pP5/4P1P4/3P1B1P3/2P2B2P2/1PRNQBKNRP1 w e6 0 2'),
|
|
831
|
+
)
|
|
832
|
+
|
|
833
|
+
setup(() => {
|
|
834
|
+
return () => (
|
|
835
|
+
<Hexboard
|
|
836
|
+
active
|
|
837
|
+
autoselect
|
|
838
|
+
playing={true}
|
|
839
|
+
hexchess={hexchess.value}
|
|
840
|
+
onMove={san => hexchess.value.applyMoveUnsafe(san)}
|
|
841
|
+
/>
|
|
842
|
+
)
|
|
843
|
+
})
|
|
844
|
+
|
|
845
|
+
await dragMove(page, 'f5e5')
|
|
846
|
+
|
|
847
|
+
await expect(hexchess.value.toString()).toBe('b/qbk/n1b1n/r5r/ppp1ppppp/11/4P6/4P1P4/3P1B1P3/2P2B2P2/1PRNQBKNRP1 b - 0 2')
|
|
832
848
|
})
|
package/src/tests/utils.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { position } from '@bedard/hexchess'
|
|
2
2
|
import { San } from '@bedard/hexchess'
|
|
3
|
+
import { expect } from 'vitest'
|
|
3
4
|
import type { BrowserPage } from 'vitest/browser'
|
|
4
5
|
import { render } from 'vitest-browser-vue'
|
|
5
6
|
import { nextTick } from 'vue'
|
|
6
7
|
|
|
7
|
-
/** make a move on the hexboard */
|
|
8
|
-
export async function
|
|
8
|
+
/** make a move on the hexboard by clicking */
|
|
9
|
+
export async function clickMove(
|
|
9
10
|
page: BrowserPage,
|
|
10
11
|
...sans: string[]
|
|
11
12
|
): Promise<void> {
|
|
@@ -20,6 +21,31 @@ export async function makeMove(
|
|
|
20
21
|
}
|
|
21
22
|
}
|
|
22
23
|
|
|
24
|
+
/** drag and drop a piece on the hexboard */
|
|
25
|
+
export async function dragMove(
|
|
26
|
+
page: BrowserPage,
|
|
27
|
+
...sans: string[]
|
|
28
|
+
): Promise<void> {
|
|
29
|
+
for (const str of sans) {
|
|
30
|
+
const san = San.from(str)
|
|
31
|
+
|
|
32
|
+
const fromPosition = page.getByTestId(`position-${position(san.from)}`)
|
|
33
|
+
const toPosition = page.getByTestId(`position-${position(san.to)}`)
|
|
34
|
+
|
|
35
|
+
await fromPosition
|
|
36
|
+
.element()
|
|
37
|
+
.dispatchEvent(new PointerEvent('pointerdown', { bubbles: true }))
|
|
38
|
+
await nextTick()
|
|
39
|
+
|
|
40
|
+
await expect.element(page.getByTestId('drag-piece')).toBeVisible()
|
|
41
|
+
|
|
42
|
+
await toPosition
|
|
43
|
+
.element()
|
|
44
|
+
.dispatchEvent(new PointerEvent('pointerup', { bubbles: true }))
|
|
45
|
+
await nextTick()
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
23
49
|
/** setup a component */
|
|
24
50
|
export function setup(setup: () => any): ReturnType<typeof render> {
|
|
25
51
|
return render({ setup })
|
package/vite.config.ts
CHANGED
|
@@ -27,7 +27,24 @@ export default defineConfig({
|
|
|
27
27
|
rollupTypes: true,
|
|
28
28
|
}),
|
|
29
29
|
tailwindcss(),
|
|
30
|
-
vue(
|
|
30
|
+
vue({
|
|
31
|
+
template: {
|
|
32
|
+
compilerOptions: {
|
|
33
|
+
nodeTransforms: [
|
|
34
|
+
(node) => {
|
|
35
|
+
// remove data-testid attributes from production build
|
|
36
|
+
if (node.type === 1 && node.props) {
|
|
37
|
+
node.props = node.props
|
|
38
|
+
.filter(prop =>
|
|
39
|
+
!(prop.type === 6 && prop.name === 'data-testid')
|
|
40
|
+
&& !(prop.type === 7 && prop.name === 'bind' && prop.arg?.type === 4 && prop.arg.content === 'data-testid'),
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
}),
|
|
31
48
|
],
|
|
32
49
|
resolve: {
|
|
33
50
|
alias: {
|