@bedard/hexboard 0.0.10 → 0.0.11
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 +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +66 -66
- package/package.json +21 -21
- package/src/lib/components/hexboard/Hexboard.vue +6 -0
- package/src/tests/hexboard.test.tsx +66 -0
package/CHANGELOG.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -12,12 +12,16 @@ import { VNode } from 'vue';
|
|
|
12
12
|
|
|
13
13
|
declare const __VLS_component: DefineComponent<__VLS_PublicProps, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {
|
|
14
14
|
clickPosition: (position: number) => any;
|
|
15
|
+
dragendPosition: (position: number) => any;
|
|
16
|
+
dragstartPosition: (position: number) => any;
|
|
15
17
|
move: (san: San) => any;
|
|
16
18
|
"update:mouseover-position": (value: number | null) => any;
|
|
17
19
|
"update:selected": (value: number | null) => any;
|
|
18
20
|
"update:targets": (value: number[]) => any;
|
|
19
21
|
}, string, PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
|
|
20
22
|
onClickPosition?: ((position: number) => any) | undefined;
|
|
23
|
+
onDragendPosition?: ((position: number) => any) | undefined;
|
|
24
|
+
onDragstartPosition?: ((position: number) => any) | undefined;
|
|
21
25
|
onMove?: ((san: San) => any) | undefined;
|
|
22
26
|
"onUpdate:mouseover-position"?: ((value: number | null) => any) | undefined;
|
|
23
27
|
"onUpdate:selected"?: ((value: number | null) => any) | undefined;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineComponent as fo,
|
|
1
|
+
import { defineComponent as fo, openBlock as x, createElementBlock as C, createElementVNode as vo, toDisplayString as ho, useModel as Zt, shallowRef as et, useTemplateRef as Co, computed as W, onBeforeMount as Eo, onMounted as Lo, onUnmounted as Bo, watch as jt, unref as a, normalizeStyle as ct, Fragment as tt, renderList as ot, mergeProps as Mo, createCommentVNode as nt, createBlock as uo, resolveDynamicComponent as io, withModifiers as $o, renderSlot as To, mergeModels as co, h as Fo } from "vue";
|
|
2
2
|
import { Hexchess as ao, position as ae, San as at, isPromotionPosition as Ro } from "@bedard/hexchess";
|
|
3
3
|
function r(i, B, v) {
|
|
4
4
|
return [i[0] + v * (B[0] - i[0]), i[1] + v * (B[1] - i[1])];
|
|
@@ -8,19 +8,19 @@ function n(i) {
|
|
|
8
8
|
}
|
|
9
9
|
function e(i) {
|
|
10
10
|
return [
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
P(i, -300, ue),
|
|
12
|
+
P(i, 0, ue),
|
|
13
|
+
P(i, -60, ue),
|
|
14
|
+
P(i, -120, ue),
|
|
15
|
+
P(i, -180, ue),
|
|
16
|
+
P(i, -240, ue)
|
|
17
17
|
];
|
|
18
18
|
}
|
|
19
|
-
function
|
|
20
|
-
const
|
|
19
|
+
function P(i, B, v) {
|
|
20
|
+
const X = So(B);
|
|
21
21
|
return [
|
|
22
|
-
v * Math.cos(
|
|
23
|
-
v * Math.sin(
|
|
22
|
+
v * Math.cos(X) + i[0],
|
|
23
|
+
v * Math.sin(X) + i[1]
|
|
24
24
|
];
|
|
25
25
|
}
|
|
26
26
|
function So(i) {
|
|
@@ -57,7 +57,7 @@ const de = 23.6, qo = {
|
|
|
57
57
|
// red-500
|
|
58
58
|
targetColor: "oklch(63.7% 0.237 25.331)"
|
|
59
59
|
// red-500
|
|
60
|
-
}, No = "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, y = p * 2, w = p * 3,
|
|
60
|
+
}, No = "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, y = p * 2, w = p * 3, k = p * 4, L = p * 5, m = [0, 0], A = P(m, 150, L), S = P(m, 150, k), D = P(m, 150, w), q = P(m, 150, y), $ = P(m, 150, p), T = P(m, 30, p), N = P(m, 30, y), H = P(m, 30, w), z = P(m, 30, k), O = P(m, 30, L), U = l(A, [0, -L]), Z = l(S, [0, -L]), he = l(D, [0, -L]), pe = l(q, [0, -L]), me = l($, [0, -L]), ge = l(m, [0, -L]), ye = l(T, [0, -L]), we = l(N, [0, -L]), be = l(H, [0, -L]), j = l(z, [0, -L]), G = l(O, [0, -L]), I = l(A, [0, -k]), J = l(S, [0, -k]), xe = l(D, [0, -k]), Pe = l(q, [0, -k]), ke = l($, [0, -k]), Ce = l(m, [0, -k]), Ee = l(T, [0, -k]), Le = l(N, [0, -k]), Be = l(H, [0, -k]), _ = l(z, [0, -k]), ee = l(O, [0, -k]), Me = l(A, [0, -w]), $e = l(S, [0, -w]), ft = l(D, [0, -w]), vt = l(q, [0, -w]), dt = l($, [0, -w]), ht = l(m, [0, -w]), pt = l(T, [0, -w]), mt = l(N, [0, -w]), gt = l(H, [0, -w]), Te = l(z, [0, -w]), Fe = l(O, [0, -w]), Re = l(A, [0, -y]), Se = l(S, [0, -y]), yt = l(D, [0, -y]), wt = l(q, [0, -y]), bt = l($, [0, -y]), xt = l(m, [0, -y]), Pt = l(T, [0, -y]), kt = l(N, [0, -y]), Ct = l(H, [0, -y]), qe = l(z, [0, -y]), Ne = l(O, [0, -y]), ze = l(A, [0, -p]), We = l(S, [0, -p]), Et = l(D, [0, -p]), Lt = l(q, [0, -p]), Bt = l($, [0, -p]), Mt = l(m, [0, -p]), $t = l(T, [0, -p]), Tt = l(N, [0, -p]), Ft = l(H, [0, -p]), Ae = l(z, [0, -p]), De = l(O, [0, -p]), He = l(S, [0, p]), Oe = l(D, [0, p]), Rt = l(q, [0, p]), St = l($, [0, p]), qt = l(m, [0, p]), Nt = l(T, [0, p]), zt = l(N, [0, p]), Xe = l(H, [0, p]), Ye = l(z, [0, p]), Ke = l(D, [0, y]), Qe = l(q, [0, y]), Wt = l($, [0, y]), At = l(m, [0, y]), Dt = l(T, [0, y]), Ve = l(N, [0, y]), Ue = l(H, [0, y]), Ze = l(q, [0, w]), je = l($, [0, w]), Ht = l(m, [0, w]), Ge = l(T, [0, w]), Ie = l(N, [0, w]), te = l($, [0, k]), oe = l(m, [0, k]), ne = l(T, [0, k]), le = l(m, [0, L]), o = [
|
|
61
61
|
[2, le, t(le), e(le), n(e(le))],
|
|
62
62
|
[1, te, t(te), e(te), n(e(te))],
|
|
63
63
|
[0, oe, t(oe), e(oe), n(e(oe))],
|
|
@@ -111,8 +111,8 @@ const de = 23.6, qo = {
|
|
|
111
111
|
[2, wt, t(wt), e(wt), n(e(wt))],
|
|
112
112
|
[1, bt, t(bt), e(bt), n(e(bt))],
|
|
113
113
|
[0, xt, t(xt), e(xt), n(e(xt))],
|
|
114
|
-
[1,
|
|
115
|
-
[2,
|
|
114
|
+
[1, Pt, t(Pt), e(Pt), n(e(Pt))],
|
|
115
|
+
[2, kt, t(kt), e(kt), n(e(kt))],
|
|
116
116
|
[0, Ct, t(Ct), e(Ct), n(e(Ct))],
|
|
117
117
|
[1, qe, t(qe), e(qe), n(e(qe))],
|
|
118
118
|
[2, Ne, t(Ne), e(Ne), n(e(Ne))],
|
|
@@ -130,8 +130,8 @@ const de = 23.6, qo = {
|
|
|
130
130
|
[1, I, t(I), e(I), n(e(I))],
|
|
131
131
|
[0, J, t(J), e(J), n(e(J))],
|
|
132
132
|
[2, xe, t(xe), e(xe), n(e(xe))],
|
|
133
|
-
[1,
|
|
134
|
-
[0,
|
|
133
|
+
[1, Pe, t(Pe), e(Pe), n(e(Pe))],
|
|
134
|
+
[0, ke, t(ke), e(ke), n(e(ke))],
|
|
135
135
|
[2, Ce, t(Ce), e(Ce), n(e(Ce))],
|
|
136
136
|
[0, Ee, t(Ee), e(Ee), n(e(Ee))],
|
|
137
137
|
[1, Le, t(Le), e(Le), n(e(Le))],
|
|
@@ -164,8 +164,8 @@ const de = 23.6, qo = {
|
|
|
164
164
|
["a", r(I, U, u), t(r(I, U, u))],
|
|
165
165
|
["b", r(J, Z, u), t(r(J, Z, u))],
|
|
166
166
|
["c", r(xe, he, u), t(r(xe, he, u))],
|
|
167
|
-
["d", r(
|
|
168
|
-
["e", r(
|
|
167
|
+
["d", r(Pe, pe, u), t(r(Pe, pe, u))],
|
|
168
|
+
["e", r(ke, me, u), t(r(ke, me, u))],
|
|
169
169
|
["f", r(Ce, ge, u), t(r(Ce, ge, u))],
|
|
170
170
|
["g", r(Ee, ye, u), t(r(Ee, ye, u))],
|
|
171
171
|
["h", r(Le, we, u), t(r(Le, we, u))],
|
|
@@ -561,10 +561,10 @@ function Ot(i) {
|
|
|
561
561
|
if (i.length === 0)
|
|
562
562
|
return "";
|
|
563
563
|
const [B, ...v] = i;
|
|
564
|
-
let
|
|
564
|
+
let X = `M ${R(fe(B[0]))} ${R(ve(B[1]))} L `;
|
|
565
565
|
for (const F of v)
|
|
566
|
-
|
|
567
|
-
return `${
|
|
566
|
+
X += `${R(fe(F[0]))} ${R(ve(F[1]))} `;
|
|
567
|
+
return `${X} Z`;
|
|
568
568
|
}
|
|
569
569
|
function R(i) {
|
|
570
570
|
return i.toFixed(8);
|
|
@@ -596,7 +596,7 @@ const Ao = {
|
|
|
596
596
|
}
|
|
597
597
|
}), Oo = ["viewBox"], Xo = ["d", "fill"], Yo = ["d", "data-hexboard-position", "fill"], Ko = ["d", "fill"], Qo = ["d", "fill"], Vo = ["textContent", "x", "y"], Uo = ["cx", "cy", "fill"], Zo = ["viewBox"], Io = /* @__PURE__ */ fo({
|
|
598
598
|
__name: "Hexboard",
|
|
599
|
-
props: /* @__PURE__ */
|
|
599
|
+
props: /* @__PURE__ */ co({
|
|
600
600
|
active: { type: Boolean, default: !1 },
|
|
601
601
|
autoselect: { type: Boolean, default: !1 },
|
|
602
602
|
flipped: { type: Boolean, default: !1 },
|
|
@@ -624,17 +624,17 @@ const Ao = {
|
|
|
624
624
|
},
|
|
625
625
|
targetsModifiers: {}
|
|
626
626
|
}),
|
|
627
|
-
emits: /* @__PURE__ */
|
|
627
|
+
emits: /* @__PURE__ */ co(["clickPosition", "dragendPosition", "dragstartPosition", "move"], ["update:mouseover-position", "update:selected", "update:targets"]),
|
|
628
628
|
setup(i, { emit: B }) {
|
|
629
|
-
const v = i,
|
|
629
|
+
const v = i, X = B, F = Zt(i, "mouseover-position"), b = Zt(i, "selected"), Y = Zt(i, "targets"), Je = et({ x: 0, y: 0 }), M = et(null), ie = et(se()), h = et({
|
|
630
630
|
hexchess: null,
|
|
631
631
|
promotionEl: null,
|
|
632
632
|
promotionFrom: null,
|
|
633
633
|
promotionTo: null,
|
|
634
634
|
selected: null
|
|
635
|
-
}), Xt = Co("svgEl"),
|
|
635
|
+
}), Xt = Co("svgEl"), K = et(se());
|
|
636
636
|
let Yt = !1;
|
|
637
|
-
const po = W(() => h.value.hexchess ? [] :
|
|
637
|
+
const po = W(() => h.value.hexchess ? [] : Y.value), ce = W(() => h.value.hexchess ? h.value.hexchess : v.hexchess ? v.hexchess : ao.init()), mo = W(() => ce.value.board.reduce(
|
|
638
638
|
(s, f, c) => (f && c !== M.value && s.push({ piece: f, index: c }), s),
|
|
639
639
|
[]
|
|
640
640
|
)), Kt = W(() => typeof h.value.selected == "number" ? null : b.value), Gt = W(() => {
|
|
@@ -642,7 +642,7 @@ const Ao = {
|
|
|
642
642
|
if (Qt.value)
|
|
643
643
|
return "grabbing";
|
|
644
644
|
if (!(!v.active || F.value === null || h.value.hexchess)) {
|
|
645
|
-
if (b.value !== null &&
|
|
645
|
+
if (b.value !== null && Y.value.includes(F.value)) {
|
|
646
646
|
const d = (s = ce.value) == null ? void 0 : s.board[b.value];
|
|
647
647
|
if (d) {
|
|
648
648
|
const g = d === d.toLowerCase() ? "b" : "w", E = ((f = ce.value) == null ? void 0 : f.turn) === g;
|
|
@@ -654,9 +654,9 @@ const Ao = {
|
|
|
654
654
|
return v.playing === !0 || v.playing && Jt.value === ((c = ce.value) == null ? void 0 : c.turn) && v.playing === Jt.value ? "grab" : "pointer";
|
|
655
655
|
}
|
|
656
656
|
}), It = W(() => ({
|
|
657
|
-
x: Je.value.x -
|
|
658
|
-
y: Je.value.y -
|
|
659
|
-
})), Qt = W(() => !v.hexchess || h.value.hexchess || M.value === null ? null : v.hexchess.board[M.value]),
|
|
657
|
+
x: Je.value.x - K.value.width / 2,
|
|
658
|
+
y: Je.value.y - K.value.height / 2
|
|
659
|
+
})), Qt = W(() => !v.hexchess || h.value.hexchess || M.value === null ? null : v.hexchess.board[M.value]), Q = W(() => ({ ...qo, ...v.options })), Jt = W(() => lt.value ? lt.value === lt.value.toLowerCase() ? "b" : "w" : null), lt = W(() => {
|
|
660
660
|
var s;
|
|
661
661
|
return F.value === null ? null : ((s = ce.value) == null ? void 0 : s.board[F.value]) ?? null;
|
|
662
662
|
}), st = W(() => {
|
|
@@ -684,7 +684,7 @@ const Ao = {
|
|
|
684
684
|
), jt(b, so);
|
|
685
685
|
function Vt(s, f) {
|
|
686
686
|
var E, re;
|
|
687
|
-
if (!
|
|
687
|
+
if (!Y.value.includes(s.to))
|
|
688
688
|
return;
|
|
689
689
|
const c = (E = v.hexchess) == null ? void 0 : E.board[s.from];
|
|
690
690
|
if (!c)
|
|
@@ -715,7 +715,7 @@ const Ao = {
|
|
|
715
715
|
}
|
|
716
716
|
function go(s) {
|
|
717
717
|
var f, c;
|
|
718
|
-
return F.value === null ?
|
|
718
|
+
return F.value === null ? Q.value.labelColor : (f = ae(F.value)) != null && f.startsWith(s) || (c = ae(F.value)) != null && c.endsWith(s) ? Q.value.labelActiveColor : Q.value.labelInactiveColor;
|
|
719
719
|
}
|
|
720
720
|
function rt(s) {
|
|
721
721
|
var d;
|
|
@@ -742,12 +742,12 @@ const Ao = {
|
|
|
742
742
|
h.value.selected !== s && _e();
|
|
743
743
|
return;
|
|
744
744
|
}
|
|
745
|
-
if (b.value !== null &&
|
|
745
|
+
if (b.value !== null && Y.value.includes(s)) {
|
|
746
746
|
const c = new at({ from: b.value, to: s });
|
|
747
747
|
Vt(c, f);
|
|
748
748
|
return;
|
|
749
749
|
}
|
|
750
|
-
v.autoselect && !v.hexchess.board[s] && (b.value = null),
|
|
750
|
+
v.autoselect && !v.hexchess.board[s] && (b.value = null), X("clickPosition", s);
|
|
751
751
|
}
|
|
752
752
|
}
|
|
753
753
|
function eo(s) {
|
|
@@ -766,22 +766,22 @@ const Ao = {
|
|
|
766
766
|
F.value = null;
|
|
767
767
|
}
|
|
768
768
|
function to(s) {
|
|
769
|
-
|
|
769
|
+
X("move", s), it();
|
|
770
770
|
}
|
|
771
771
|
function xo(s, f) {
|
|
772
772
|
var E, re;
|
|
773
|
-
if (f.preventDefault(), h.value.hexchess || b.value !== null &&
|
|
773
|
+
if (f.preventDefault(), h.value.hexchess || b.value !== null && Y.value.includes(s))
|
|
774
774
|
return;
|
|
775
775
|
const c = (E = v.hexchess) == null ? void 0 : E.board[s];
|
|
776
776
|
if (!c || (v.autoselect && (b.value = s), !rt(s)))
|
|
777
777
|
return;
|
|
778
778
|
const d = c === c.toLowerCase() ? "b" : "w", g = ((re = v.hexchess) == null ? void 0 : re.turn) === d;
|
|
779
|
-
!v.ignoreTurn && !g || (M.value = s, Je.value = { x: f.clientX, y: f.clientY }, Xt.value instanceof Element && (
|
|
779
|
+
!v.ignoreTurn && !g || (M.value = s, Je.value = { x: f.clientX, y: f.clientY }, Xt.value instanceof Element && (K.value = Xt.value.getBoundingClientRect()), X("dragstartPosition", s));
|
|
780
780
|
}
|
|
781
781
|
function oo(s) {
|
|
782
782
|
v.active && (Je.value = { x: s.clientX, y: s.clientY });
|
|
783
783
|
}
|
|
784
|
-
function
|
|
784
|
+
function Po(s, f) {
|
|
785
785
|
var c;
|
|
786
786
|
if (f.stopPropagation(), M.value !== null) {
|
|
787
787
|
let d = s;
|
|
@@ -789,14 +789,14 @@ const Ao = {
|
|
|
789
789
|
f.clientX,
|
|
790
790
|
f.clientY
|
|
791
791
|
), E = g == null ? void 0 : g.getAttribute("data-hexboard-position");
|
|
792
|
-
E !== null && (d = Number(E));
|
|
792
|
+
E !== null && (d = Number(E)), X("dragendPosition", d);
|
|
793
793
|
const re = new at({ from: M.value, to: d });
|
|
794
794
|
if (Vt(re, f), h.value.hexchess)
|
|
795
795
|
return;
|
|
796
|
-
M.value = null,
|
|
796
|
+
M.value = null, K.value = se();
|
|
797
797
|
return;
|
|
798
798
|
}
|
|
799
|
-
if (b.value !== null &&
|
|
799
|
+
if (b.value !== null && Y.value.includes(s)) {
|
|
800
800
|
const d = new at({ from: b.value, to: s });
|
|
801
801
|
return Vt(d, f), h.value.hexchess, void 0;
|
|
802
802
|
}
|
|
@@ -805,7 +805,7 @@ const Ao = {
|
|
|
805
805
|
return;
|
|
806
806
|
}
|
|
807
807
|
if ((c = v.hexchess) != null && c.board[s]) {
|
|
808
|
-
M.value = null,
|
|
808
|
+
M.value = null, K.value = se();
|
|
809
809
|
return;
|
|
810
810
|
}
|
|
811
811
|
it();
|
|
@@ -816,7 +816,7 @@ const Ao = {
|
|
|
816
816
|
return;
|
|
817
817
|
}
|
|
818
818
|
if (M.value !== null) {
|
|
819
|
-
M.value = null,
|
|
819
|
+
M.value = null, K.value = se();
|
|
820
820
|
return;
|
|
821
821
|
}
|
|
822
822
|
it();
|
|
@@ -824,7 +824,7 @@ const Ao = {
|
|
|
824
824
|
function lo(s) {
|
|
825
825
|
M.value !== null && s.preventDefault();
|
|
826
826
|
}
|
|
827
|
-
function
|
|
827
|
+
function ko(s) {
|
|
828
828
|
if (typeof h.value.promotionFrom == "number" && rt(h.value.promotionFrom)) {
|
|
829
829
|
const f = new at({
|
|
830
830
|
from: h.value.promotionFrom ?? 0,
|
|
@@ -853,11 +853,11 @@ const Ao = {
|
|
|
853
853
|
promotionFrom: null,
|
|
854
854
|
promotionTo: null,
|
|
855
855
|
selected: null
|
|
856
|
-
},
|
|
856
|
+
}, K.value = se(), Y.value = [];
|
|
857
857
|
}
|
|
858
858
|
function so() {
|
|
859
859
|
var s;
|
|
860
|
-
typeof b.value == "number" ?
|
|
860
|
+
typeof b.value == "number" ? Y.value = ((s = v.hexchess) == null ? void 0 : s.movesFrom(b.value).map((f) => f.to)) ?? [] : Y.value = [];
|
|
861
861
|
}
|
|
862
862
|
function ro() {
|
|
863
863
|
it(), window.removeEventListener("keyup", eo), window.removeEventListener("pointermove", oo), window.removeEventListener("pointerup", no), window.removeEventListener("resize", ut), window.removeEventListener("scroll", ut), window.removeEventListener("touchmove", lo);
|
|
@@ -872,39 +872,39 @@ const Ao = {
|
|
|
872
872
|
}, [
|
|
873
873
|
vo("path", {
|
|
874
874
|
d: a(Ot)(a(Wo)),
|
|
875
|
-
fill:
|
|
875
|
+
fill: Q.value.colors[1],
|
|
876
876
|
style: { pointerEvents: "none" }
|
|
877
877
|
}, null, 8, Xo),
|
|
878
|
-
(x(!0), C(
|
|
878
|
+
(x(!0), C(tt, null, ot(a(o), (c, d) => (x(), C("path", Mo(
|
|
879
879
|
{ ref_for: !0 },
|
|
880
880
|
i.active ? {
|
|
881
881
|
onClick: (g) => yo(d, g),
|
|
882
882
|
onMouseenter: () => wo(d),
|
|
883
883
|
onMouseleave: () => bo(),
|
|
884
884
|
onPointerdown: (g) => xo(d, g),
|
|
885
|
-
onPointerup: (g) =>
|
|
885
|
+
onPointerup: (g) => Po(d, g)
|
|
886
886
|
} : {},
|
|
887
887
|
{
|
|
888
888
|
d: a(Ot)(i.flipped ? c[4] : c[3]),
|
|
889
889
|
"data-hexboard-position": d,
|
|
890
|
-
fill:
|
|
890
|
+
fill: Q.value.colors[a(o)[d][0]],
|
|
891
891
|
key: d
|
|
892
892
|
}
|
|
893
893
|
), null, 16, Yo))), 128)),
|
|
894
|
-
(x(!0), C(
|
|
894
|
+
(x(!0), C(tt, null, ot(i.highlight, (c) => (x(), C("path", {
|
|
895
895
|
d: a(Ot)(i.flipped ? a(o)[c][4] : a(o)[c][3]),
|
|
896
|
-
fill:
|
|
896
|
+
fill: Q.value.highlightColor,
|
|
897
897
|
key: `highlight-${c}`,
|
|
898
898
|
style: { pointerEvents: "none" }
|
|
899
899
|
}, null, 8, Ko))), 128)),
|
|
900
900
|
typeof Kt.value == "number" ? (x(), C("path", {
|
|
901
901
|
key: 0,
|
|
902
902
|
d: a(Ot)(i.flipped ? a(o)[Kt.value][4] : a(o)[Kt.value][3]),
|
|
903
|
-
fill:
|
|
903
|
+
fill: Q.value.selectedColor,
|
|
904
904
|
ref: "selectedEl",
|
|
905
905
|
style: { pointerEvents: "none" }
|
|
906
|
-
}, null, 8, Qo)) :
|
|
907
|
-
|
|
906
|
+
}, null, 8, Qo)) : nt("", !0),
|
|
907
|
+
Q.value.labels ? (x(!0), C(tt, { key: 1 }, ot(a(zo), ([c, d, g], E) => (x(), C("text", {
|
|
908
908
|
textContent: ho(c),
|
|
909
909
|
"dominant-baseline": "central",
|
|
910
910
|
"text-anchor": "middle",
|
|
@@ -917,8 +917,8 @@ const Ao = {
|
|
|
917
917
|
}),
|
|
918
918
|
x: a(R)(a(fe)(i.flipped ? g[0] : d[0])),
|
|
919
919
|
y: a(R)(a(ve)(i.flipped ? g[1] : d[1]))
|
|
920
|
-
}, null, 12, Vo))), 128)) :
|
|
921
|
-
ce.value ? (x(!0), C(
|
|
920
|
+
}, null, 12, Vo))), 128)) : nt("", !0),
|
|
921
|
+
ce.value ? (x(!0), C(tt, { key: 2 }, ot(mo.value, ({ piece: c, index: d }) => (x(), uo(io(i.pieces), {
|
|
922
922
|
"data-piece-type": c,
|
|
923
923
|
height: a(V),
|
|
924
924
|
key: `piece-${a(ae)(d)}`,
|
|
@@ -927,11 +927,11 @@ const Ao = {
|
|
|
927
927
|
width: a(V),
|
|
928
928
|
x: a(R)(a(fe)(a(o)[d][i.flipped ? 2 : 1][0] - a(V) / 2)),
|
|
929
929
|
y: a(R)(a(ve)(a(o)[d][i.flipped ? 2 : 1][1] + a(V) / 2))
|
|
930
|
-
}, null, 8, ["data-piece-type", "height", "type", "width", "x", "y"]))), 128)) :
|
|
931
|
-
(x(!0), C(
|
|
930
|
+
}, null, 8, ["data-piece-type", "height", "type", "width", "x", "y"]))), 128)) : nt("", !0),
|
|
931
|
+
(x(!0), C(tt, null, ot(po.value, (c) => (x(), C("circle", {
|
|
932
932
|
cx: a(R)(a(fe)(a(o)[c][i.flipped ? 2 : 1][0])),
|
|
933
933
|
cy: a(R)(a(ve)(a(o)[c][i.flipped ? 2 : 1][1])),
|
|
934
|
-
fill:
|
|
934
|
+
fill: Q.value.targetColor,
|
|
935
935
|
key: `target-${a(ae)(c)}`,
|
|
936
936
|
r: 0.3,
|
|
937
937
|
style: { pointerEvents: "none" }
|
|
@@ -941,18 +941,18 @@ const Ao = {
|
|
|
941
941
|
key: 0,
|
|
942
942
|
xmlns: "http://www.w3.org/2000/svg",
|
|
943
943
|
style: ct({
|
|
944
|
-
height:
|
|
944
|
+
height: K.value.height + "px",
|
|
945
945
|
left: "0px",
|
|
946
946
|
pointerEvents: "none",
|
|
947
947
|
position: "fixed",
|
|
948
948
|
top: "0px",
|
|
949
949
|
transform: `translate(${It.value.x}px, ${It.value.y}px) scale(1.1)`,
|
|
950
|
-
width:
|
|
950
|
+
width: K.value.width + "px",
|
|
951
951
|
willChange: "transform"
|
|
952
952
|
}),
|
|
953
953
|
viewBox: `0 0 ${a(de)} ${a(de)}`
|
|
954
954
|
}, [
|
|
955
|
-
(x(), io(
|
|
955
|
+
(x(), uo(io(i.pieces), {
|
|
956
956
|
height: a(V),
|
|
957
957
|
style: { pointerEvents: "none" },
|
|
958
958
|
type: Qt.value,
|
|
@@ -960,7 +960,7 @@ const Ao = {
|
|
|
960
960
|
x: a(R)(a(fe)(a(V) / -2)),
|
|
961
961
|
y: a(R)(a(ve)(a(V) / 2))
|
|
962
962
|
}, null, 8, ["height", "type", "width", "x", "y"]))
|
|
963
|
-
], 12, Zo)) :
|
|
963
|
+
], 12, Zo)) : nt("", !0),
|
|
964
964
|
typeof h.value.selected == "number" ? (x(), C("div", {
|
|
965
965
|
key: 1,
|
|
966
966
|
style: ct({
|
|
@@ -978,12 +978,12 @@ const Ao = {
|
|
|
978
978
|
cancel: _e,
|
|
979
979
|
file: a(ae)(h.value.selected)[0],
|
|
980
980
|
n: st.value.n,
|
|
981
|
-
promote:
|
|
981
|
+
promote: ko,
|
|
982
982
|
q: st.value.q,
|
|
983
983
|
r: st.value.r,
|
|
984
984
|
rank: Number(a(ae)(h.value.selected).slice(1))
|
|
985
985
|
})
|
|
986
|
-
], 36)) :
|
|
986
|
+
], 36)) : nt("", !0)
|
|
987
987
|
]));
|
|
988
988
|
}
|
|
989
989
|
});
|
package/package.json
CHANGED
|
@@ -3,34 +3,34 @@
|
|
|
3
3
|
"description": "Component library for hexchess.club",
|
|
4
4
|
"devDependencies": {
|
|
5
5
|
"@bedard/hexchess": "^2.5.1",
|
|
6
|
-
"@eslint/js": "^9.39.
|
|
6
|
+
"@eslint/js": "^9.39.3",
|
|
7
7
|
"@headlessui/vue": "^1.7.23",
|
|
8
8
|
"@heroicons/vue": "^2.2.0",
|
|
9
|
-
"@stylistic/eslint-plugin": "^5.
|
|
10
|
-
"@tailwindcss/vite": "^4.1
|
|
11
|
-
"@types/node": "^22.19.
|
|
12
|
-
"@vitejs/plugin-vue": "^6.0.
|
|
13
|
-
"@vitejs/plugin-vue-jsx": "^5.1.
|
|
14
|
-
"@vitest/browser": "^4.0.
|
|
15
|
-
"@vitest/browser-playwright": "^4.0.
|
|
16
|
-
"@vitest/coverage-v8": "^4.0.
|
|
17
|
-
"@vitest/ui": "^4.0.
|
|
9
|
+
"@stylistic/eslint-plugin": "^5.9.0",
|
|
10
|
+
"@tailwindcss/vite": "^4.2.1",
|
|
11
|
+
"@types/node": "^22.19.12",
|
|
12
|
+
"@vitejs/plugin-vue": "^6.0.4",
|
|
13
|
+
"@vitejs/plugin-vue-jsx": "^5.1.4",
|
|
14
|
+
"@vitest/browser": "^4.0.18",
|
|
15
|
+
"@vitest/browser-playwright": "^4.0.18",
|
|
16
|
+
"@vitest/coverage-v8": "^4.0.18",
|
|
17
|
+
"@vitest/ui": "^4.0.18",
|
|
18
18
|
"@vue/test-utils": "^2.4.6",
|
|
19
|
-
"eslint": "^9.39.
|
|
19
|
+
"eslint": "^9.39.3",
|
|
20
20
|
"eslint-plugin-simple-import-sort": "^12.1.1",
|
|
21
|
-
"eslint-plugin-vue": "^10.
|
|
21
|
+
"eslint-plugin-vue": "^10.8.0",
|
|
22
22
|
"globals": "^16.5.0",
|
|
23
|
-
"jsdom": "^27.
|
|
24
|
-
"playwright": "^1.
|
|
25
|
-
"tailwindcss": "^4.1
|
|
23
|
+
"jsdom": "^27.4.0",
|
|
24
|
+
"playwright": "^1.58.2",
|
|
25
|
+
"tailwindcss": "^4.2.1",
|
|
26
26
|
"typescript": "^5.9.3",
|
|
27
|
-
"typescript-eslint": "^8.
|
|
27
|
+
"typescript-eslint": "^8.56.1",
|
|
28
28
|
"vite": "^6.4.1",
|
|
29
29
|
"vite-plugin-dts": "^4.5.4",
|
|
30
|
-
"vitest": "^4.0.
|
|
31
|
-
"vitest-browser-vue": "^2.0.
|
|
32
|
-
"vue": "^3.5.
|
|
33
|
-
"vue-tsc": "^3.
|
|
30
|
+
"vitest": "^4.0.18",
|
|
31
|
+
"vitest-browser-vue": "^2.0.2",
|
|
32
|
+
"vue": "^3.5.29",
|
|
33
|
+
"vue-tsc": "^3.2.5"
|
|
34
34
|
},
|
|
35
35
|
"keywords": [
|
|
36
36
|
"hexchess"
|
|
@@ -58,5 +58,5 @@
|
|
|
58
58
|
"license": "MIT",
|
|
59
59
|
"type": "module",
|
|
60
60
|
"types": "dist/index.d.ts",
|
|
61
|
-
"version": "0.0.
|
|
61
|
+
"version": "0.0.11"
|
|
62
62
|
}
|
|
@@ -231,6 +231,8 @@ const props = withDefaults(
|
|
|
231
231
|
|
|
232
232
|
const emit = defineEmits<{
|
|
233
233
|
clickPosition: [position: number]
|
|
234
|
+
dragendPosition: [position: number]
|
|
235
|
+
dragstartPosition: [position: number]
|
|
234
236
|
move: [san: San]
|
|
235
237
|
}>()
|
|
236
238
|
|
|
@@ -725,6 +727,8 @@ function onPointerdownPosition(index: number, evt: PointerEvent) {
|
|
|
725
727
|
if (svgEl.value instanceof Element) {
|
|
726
728
|
svgRect.value = svgEl.value.getBoundingClientRect()
|
|
727
729
|
}
|
|
730
|
+
|
|
731
|
+
emit('dragstartPosition', index)
|
|
728
732
|
}
|
|
729
733
|
|
|
730
734
|
/** pointermove window */
|
|
@@ -755,6 +759,8 @@ function onPointerupPosition(index: number, evt: PointerEvent) {
|
|
|
755
759
|
targetIndex = Number(posAttr)
|
|
756
760
|
}
|
|
757
761
|
|
|
762
|
+
emit('dragendPosition', targetIndex)
|
|
763
|
+
|
|
758
764
|
const san = new San({ from: pointerdownPosition.value, to: targetIndex })
|
|
759
765
|
attemptMove(san, evt)
|
|
760
766
|
|
|
@@ -502,6 +502,72 @@ test('dragging piece off board results in selection only, dragging state resets'
|
|
|
502
502
|
await expect.element(page.getByTestId('drag-piece')).not.toBeInTheDocument()
|
|
503
503
|
})
|
|
504
504
|
|
|
505
|
+
test('drag emits dragstartPosition and dragendPosition', async () => {
|
|
506
|
+
const selected = ref<number | null>(null)
|
|
507
|
+
const targets = ref<number[]>([])
|
|
508
|
+
const onDragstartPosition = vi.fn()
|
|
509
|
+
const onDragendPosition = vi.fn()
|
|
510
|
+
|
|
511
|
+
setup(() => {
|
|
512
|
+
return () => (
|
|
513
|
+
<Hexboard
|
|
514
|
+
active
|
|
515
|
+
autoselect
|
|
516
|
+
playing="w"
|
|
517
|
+
v-model:selected={selected.value}
|
|
518
|
+
v-model:targets={targets.value}
|
|
519
|
+
onDragendPosition={onDragendPosition}
|
|
520
|
+
onDragstartPosition={onDragstartPosition}
|
|
521
|
+
/>
|
|
522
|
+
)
|
|
523
|
+
})
|
|
524
|
+
|
|
525
|
+
await dragMove(page, 'f5f6')
|
|
526
|
+
|
|
527
|
+
await expect(onDragstartPosition).toHaveBeenCalledOnce()
|
|
528
|
+
await expect(onDragstartPosition).toHaveBeenCalledWith(index('f5'))
|
|
529
|
+
await expect(onDragendPosition).toHaveBeenCalledOnce()
|
|
530
|
+
await expect(onDragendPosition).toHaveBeenCalledWith(index('f6'))
|
|
531
|
+
})
|
|
532
|
+
|
|
533
|
+
test('drag start emits dragstartPosition; release off board does not emit dragendPosition', async () => {
|
|
534
|
+
const selected = ref<number | null>(null)
|
|
535
|
+
const targets = ref<number[]>([])
|
|
536
|
+
const onDragstartPosition = vi.fn()
|
|
537
|
+
const onDragendPosition = vi.fn()
|
|
538
|
+
|
|
539
|
+
setup(() => {
|
|
540
|
+
return () => (
|
|
541
|
+
<Hexboard
|
|
542
|
+
active
|
|
543
|
+
autoselect
|
|
544
|
+
playing="w"
|
|
545
|
+
v-model:selected={selected.value}
|
|
546
|
+
v-model:targets={targets.value}
|
|
547
|
+
onDragendPosition={onDragendPosition}
|
|
548
|
+
onDragstartPosition={onDragstartPosition}
|
|
549
|
+
/>
|
|
550
|
+
)
|
|
551
|
+
})
|
|
552
|
+
|
|
553
|
+
const whitePiecePosition = page.getByTestId('position-f5')
|
|
554
|
+
|
|
555
|
+
await whitePiecePosition
|
|
556
|
+
.element()
|
|
557
|
+
.dispatchEvent(new PointerEvent('pointerdown', { bubbles: true }))
|
|
558
|
+
await nextTick()
|
|
559
|
+
|
|
560
|
+
await expect(onDragstartPosition).toHaveBeenCalledOnce()
|
|
561
|
+
await expect(onDragstartPosition).toHaveBeenCalledWith(index('f5'))
|
|
562
|
+
await expect(onDragendPosition).not.toHaveBeenCalled()
|
|
563
|
+
|
|
564
|
+
window.dispatchEvent(new PointerEvent('pointerup', { bubbles: true }))
|
|
565
|
+
await nextTick()
|
|
566
|
+
|
|
567
|
+
await expect(onDragstartPosition).toHaveBeenCalledOnce()
|
|
568
|
+
await expect(onDragendPosition).not.toHaveBeenCalled()
|
|
569
|
+
})
|
|
570
|
+
|
|
505
571
|
test('drag and drop piece emits move event', async () => {
|
|
506
572
|
const selected = ref<number | null>(null)
|
|
507
573
|
const targets = ref<number[]>([])
|