cm-chessboard 7.0.3 → 7.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/assets/extensions/markers/markers.css +18 -10
- package/assets/extensions/markers/markers.css.map +1 -1
- package/assets/extensions/markers/markers.scss +31 -13
- package/examples/extensions/markers-extension.html +6 -5
- package/package.json +1 -1
- package/src/cm-chessboard/extensions/markers/Markers.js +7 -3
- package/src/cm-chessboard/view/VisualMoveInput.js +26 -19
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ in [chess-console](https://shaack.com/projekte/chess-console/examples/load-pgn.h
|
|
|
8
8
|
[cm-fen-editor](https://shaack.com/projekte/cm-fen-editor/). They are all nice written ES6 Modules to handle different
|
|
9
9
|
aspects of chess games.
|
|
10
10
|
|
|
11
|
-
> Note: With version 7, I made a heavy allover refactoring. The chessboard props have been changed and the files structure also. Version 7 of the chessboard will not work out of the box
|
|
11
|
+
> Note: With version 7, I made a heavy allover refactoring. The chessboard props have been changed and the files structure also. Version 7 of the cm-chessboard will not work out of the box after an update from a previous version. Also with version 7 comes the move cancelling via secondary mouse button.
|
|
12
12
|
|
|
13
13
|
## Features
|
|
14
14
|
|
|
@@ -1,26 +1,34 @@
|
|
|
1
1
|
.cm-chessboard .markers {
|
|
2
2
|
pointer-events: none; }
|
|
3
3
|
.cm-chessboard .markers .marker.marker-frame {
|
|
4
|
-
stroke:
|
|
4
|
+
stroke: #000000;
|
|
5
5
|
stroke-width: 1.8px;
|
|
6
6
|
opacity: 0.5; }
|
|
7
|
-
.cm-chessboard .markers .marker.marker-frame-
|
|
7
|
+
.cm-chessboard .markers .marker.marker-frame-primary {
|
|
8
|
+
stroke: #0009bd;
|
|
9
|
+
stroke-width: 1.8px;
|
|
10
|
+
opacity: 0.4; }
|
|
11
|
+
.cm-chessboard .markers .marker.marker-frame-danger {
|
|
8
12
|
stroke: #aa0000;
|
|
9
13
|
stroke-width: 1.8px;
|
|
10
14
|
opacity: 0.4; }
|
|
11
|
-
.cm-chessboard .markers .marker.marker-square {
|
|
12
|
-
fill: black;
|
|
13
|
-
opacity: 0.11; }
|
|
14
|
-
.cm-chessboard .markers .marker.marker-dot {
|
|
15
|
-
fill: black;
|
|
16
|
-
opacity: 0.3; }
|
|
17
15
|
.cm-chessboard .markers .marker.marker-circle {
|
|
18
|
-
stroke: #
|
|
16
|
+
stroke: #000000;
|
|
19
17
|
stroke-width: 3px;
|
|
20
18
|
opacity: 0.4; }
|
|
21
|
-
.cm-chessboard .markers .marker.marker-circle-
|
|
19
|
+
.cm-chessboard .markers .marker.marker-circle-primary {
|
|
20
|
+
stroke: #0009bd;
|
|
21
|
+
stroke-width: 3px;
|
|
22
|
+
opacity: 0.4; }
|
|
23
|
+
.cm-chessboard .markers .marker.marker-circle-danger {
|
|
22
24
|
stroke: #aa0000;
|
|
23
25
|
stroke-width: 3px;
|
|
24
26
|
opacity: 0.4; }
|
|
27
|
+
.cm-chessboard .markers .marker.marker-square {
|
|
28
|
+
fill: black;
|
|
29
|
+
opacity: 0.11; }
|
|
30
|
+
.cm-chessboard .markers .marker.marker-dot {
|
|
31
|
+
fill: black;
|
|
32
|
+
opacity: 0.3; }
|
|
25
33
|
|
|
26
34
|
/*# sourceMappingURL=markers.css.map */
|
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
"markers.scss"
|
|
6
6
|
],
|
|
7
7
|
"names": [],
|
|
8
|
-
"mappings": "
|
|
8
|
+
"mappings": "AAIA,AACE,cADY,CACZ,QAAQ,CAAC;EACP,cAAc,EAAE,IAAI,GAkDrB;EApDH,AAKM,cALQ,CACZ,QAAQ,CAGN,OAAO,AACJ,aAAa,CAAC;IACb,MAAM,EAVC,OAAO;IAWd,YAAY,EAAE,KAAK;IACnB,OAAO,EAAE,GAAG,GACb;EATP,AAWM,cAXQ,CACZ,QAAQ,CAGN,OAAO,AAOJ,qBAAqB,CAAC;IACrB,MAAM,EAfS,OAAO;IAgBtB,YAAY,EAAE,KAAK;IACnB,OAAO,EAAE,GAAG,GACb;EAfP,AAiBM,cAjBQ,CACZ,QAAQ,CAGN,OAAO,AAaJ,oBAAoB,CAAC;IACpB,MAAM,EApBQ,OAAO;IAqBrB,YAAY,EAAE,KAAK;IACnB,OAAO,EAAE,GAAG,GACb;EArBP,AAuBM,cAvBQ,CACZ,QAAQ,CAGN,OAAO,AAmBJ,cAAc,CAAC;IACd,MAAM,EA5BC,OAAO;IA6Bd,YAAY,EAAE,GAAG;IACjB,OAAO,EAAE,GAAG,GACb;EA3BP,AA6BM,cA7BQ,CACZ,QAAQ,CAGN,OAAO,AAyBJ,sBAAsB,CAAC;IACtB,MAAM,EAjCS,OAAO;IAkCtB,YAAY,EAAE,GAAG;IACjB,OAAO,EAAE,GAAG,GACb;EAjCP,AAmCM,cAnCQ,CACZ,QAAQ,CAGN,OAAO,AA+BJ,qBAAqB,CAAC;IACrB,MAAM,EAtCQ,OAAO;IAuCrB,YAAY,EAAE,GAAG;IACjB,OAAO,EAAE,GAAG,GACb;EAvCP,AAyCM,cAzCQ,CACZ,QAAQ,CAGN,OAAO,AAqCJ,cAAc,CAAC;IACd,IAAI,EAAE,KAAK;IACX,OAAO,EAAE,IAAI,GACd;EA5CP,AA8CM,cA9CQ,CACZ,QAAQ,CAGN,OAAO,AA0CJ,WAAW,CAAC;IACX,IAAI,EAAE,KAAK;IACX,OAAO,EAAE,GAAG,GACb"
|
|
9
9
|
}
|
|
@@ -1,40 +1,58 @@
|
|
|
1
|
+
$marker-color: #000000;
|
|
2
|
+
$marker-color-primary: #0009bd;
|
|
3
|
+
$marker-color-danger: #aa0000;
|
|
4
|
+
|
|
1
5
|
.cm-chessboard {
|
|
2
6
|
.markers {
|
|
3
7
|
pointer-events: none;
|
|
8
|
+
|
|
4
9
|
.marker {
|
|
5
10
|
&.marker-frame {
|
|
6
|
-
stroke:
|
|
11
|
+
stroke: $marker-color;
|
|
7
12
|
stroke-width: 1.8px;
|
|
8
13
|
opacity: 0.5;
|
|
9
14
|
}
|
|
10
15
|
|
|
11
|
-
&.marker-frame-
|
|
12
|
-
stroke:
|
|
16
|
+
&.marker-frame-primary {
|
|
17
|
+
stroke: $marker-color-primary;
|
|
13
18
|
stroke-width: 1.8px;
|
|
14
19
|
opacity: 0.4;
|
|
15
20
|
}
|
|
16
21
|
|
|
17
|
-
&.marker-
|
|
18
|
-
|
|
19
|
-
|
|
22
|
+
&.marker-frame-danger {
|
|
23
|
+
stroke: $marker-color-danger;
|
|
24
|
+
stroke-width: 1.8px;
|
|
25
|
+
opacity: 0.4;
|
|
20
26
|
}
|
|
21
27
|
|
|
22
|
-
&.marker-
|
|
23
|
-
|
|
24
|
-
|
|
28
|
+
&.marker-circle {
|
|
29
|
+
stroke: $marker-color;
|
|
30
|
+
stroke-width: 3px;
|
|
31
|
+
opacity: 0.4;
|
|
25
32
|
}
|
|
26
33
|
|
|
27
|
-
&.marker-circle {
|
|
28
|
-
stroke:
|
|
34
|
+
&.marker-circle-primary {
|
|
35
|
+
stroke: $marker-color-primary;
|
|
29
36
|
stroke-width: 3px;
|
|
30
37
|
opacity: 0.4;
|
|
31
38
|
}
|
|
32
39
|
|
|
33
|
-
&.marker-circle-
|
|
34
|
-
stroke:
|
|
40
|
+
&.marker-circle-danger {
|
|
41
|
+
stroke: $marker-color-danger;
|
|
35
42
|
stroke-width: 3px;
|
|
36
43
|
opacity: 0.4;
|
|
37
44
|
}
|
|
45
|
+
|
|
46
|
+
&.marker-square {
|
|
47
|
+
fill: black;
|
|
48
|
+
opacity: 0.11;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
&.marker-dot {
|
|
52
|
+
fill: black;
|
|
53
|
+
opacity: 0.3;
|
|
54
|
+
}
|
|
55
|
+
|
|
38
56
|
}
|
|
39
57
|
}
|
|
40
58
|
}
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
if (event.type === SQUARE_SELECT_TYPE.primary) {
|
|
32
32
|
markerType = MARKER_TYPE.dot
|
|
33
33
|
} else {
|
|
34
|
-
markerType = MARKER_TYPE.
|
|
34
|
+
markerType = MARKER_TYPE.circlePrimary
|
|
35
35
|
}
|
|
36
36
|
const markersOnSquare = board1.getMarkers(markerType, event.square)
|
|
37
37
|
if (markersOnSquare.length > 0) {
|
|
@@ -54,14 +54,15 @@
|
|
|
54
54
|
board2.enableMoveInput(() => {
|
|
55
55
|
return true
|
|
56
56
|
})
|
|
57
|
-
|
|
57
|
+
// define your own marker
|
|
58
|
+
const myOwnMarker = {class: "marker-circle-danger", slice: "markerCircle"}
|
|
58
59
|
board2.enableSquareSelect((event) => {
|
|
59
60
|
if (event.type === SQUARE_SELECT_TYPE.secondary && event.mouseEvent.type === "mousedown") {
|
|
60
|
-
const markersOnSquare = board2.getMarkers(
|
|
61
|
+
const markersOnSquare = board2.getMarkers(myOwnMarker, event.square)
|
|
61
62
|
if (markersOnSquare.length > 0) {
|
|
62
|
-
board2.removeMarkers(
|
|
63
|
+
board2.removeMarkers(myOwnMarker, event.square)
|
|
63
64
|
} else {
|
|
64
|
-
board2.addMarker(
|
|
65
|
+
board2.addMarker(myOwnMarker, event.square)
|
|
65
66
|
}
|
|
66
67
|
}
|
|
67
68
|
})
|
package/package.json
CHANGED
|
@@ -9,10 +9,14 @@ import {Svg} from "../../lib/Svg.js"
|
|
|
9
9
|
import {INPUT_EVENT_TYPE} from "../../Chessboard.js"
|
|
10
10
|
|
|
11
11
|
export const MARKER_TYPE = {
|
|
12
|
-
square: {class: "marker-square", slice: "markerSquare"},
|
|
13
12
|
frame: {class: "marker-frame", slice: "markerFrame"},
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
framePrimary: {class: "marker-frame-primary", slice: "markerFrame"},
|
|
14
|
+
frameDanger: {class: "marker-frame-danger", slice: "markerFrame"},
|
|
15
|
+
circle: {class: "marker-circle", slice: "markerCircle"},
|
|
16
|
+
circlePrimary: {class: "marker-circle-primary", slice: "markerCircle"},
|
|
17
|
+
circleDanger: {class: "marker-circle-danger", slice: "markerCircle"},
|
|
18
|
+
square: {class: "marker-square", slice: "markerSquare"},
|
|
19
|
+
dot: {class: "marker-dot", slice: "markerDot", position: 'above'}
|
|
16
20
|
}
|
|
17
21
|
|
|
18
22
|
export class Markers extends Extension {
|
|
@@ -19,10 +19,11 @@ const STATE = {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export const MOVE_CANCELED_REASON = {
|
|
22
|
-
secondClick: "secondClick",
|
|
22
|
+
secondClick: "secondClick", // clicked the same piece
|
|
23
|
+
secondaryClick: "secondaryClick", // right click while moving
|
|
23
24
|
movedOutOfBoard: "movedOutOfBoard",
|
|
24
|
-
draggedBack: "draggedBack",
|
|
25
|
-
clickedAnotherPiece: "clickedAnotherPiece"
|
|
25
|
+
draggedBack: "draggedBack", // dragged to the start square
|
|
26
|
+
clickedAnotherPiece: "clickedAnotherPiece" // of the same color
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
const DRAG_THRESHOLD = 4
|
|
@@ -84,30 +85,29 @@ export class VisualMoveInput {
|
|
|
84
85
|
this.startPoint = params.point
|
|
85
86
|
if (!this.pointerMoveListener && !this.pointerUpListener) {
|
|
86
87
|
if (params.type === "mousedown") {
|
|
87
|
-
|
|
88
88
|
this.pointerMoveListener = this.onPointerMove.bind(this)
|
|
89
89
|
this.pointerMoveListener.type = "mousemove"
|
|
90
90
|
addEventListener("mousemove", this.pointerMoveListener)
|
|
91
|
-
|
|
92
91
|
this.pointerUpListener = this.onPointerUp.bind(this)
|
|
93
92
|
this.pointerUpListener.type = "mouseup"
|
|
94
93
|
addEventListener("mouseup", this.pointerUpListener)
|
|
95
|
-
|
|
96
94
|
} else if (params.type === "touchstart") {
|
|
97
|
-
|
|
98
95
|
this.pointerMoveListener = this.onPointerMove.bind(this)
|
|
99
96
|
this.pointerMoveListener.type = "touchmove"
|
|
100
97
|
addEventListener("touchmove", this.pointerMoveListener)
|
|
101
|
-
|
|
102
98
|
this.pointerUpListener = this.onPointerUp.bind(this)
|
|
103
99
|
this.pointerUpListener.type = "touchend"
|
|
104
100
|
addEventListener("touchend", this.pointerUpListener)
|
|
105
|
-
|
|
106
101
|
} else {
|
|
107
|
-
throw Error("
|
|
102
|
+
throw Error("4b74af")
|
|
103
|
+
}
|
|
104
|
+
if(this.contextMenuListener) {
|
|
105
|
+
throw Error("bd272c")
|
|
108
106
|
}
|
|
107
|
+
this.contextMenuListener = this.onContextMenu.bind(this)
|
|
108
|
+
addEventListener("contextmenu", this.contextMenuListener)
|
|
109
109
|
} else {
|
|
110
|
-
throw Error("
|
|
110
|
+
throw Error("94ad0c")
|
|
111
111
|
}
|
|
112
112
|
break
|
|
113
113
|
|
|
@@ -189,18 +189,22 @@ export class VisualMoveInput {
|
|
|
189
189
|
removeEventListener(this.pointerUpListener.type, this.pointerUpListener)
|
|
190
190
|
this.pointerUpListener = undefined
|
|
191
191
|
}
|
|
192
|
+
if (this.contextMenuListener) {
|
|
193
|
+
removeEventListener("contextmenu", this.contextMenuListener)
|
|
194
|
+
this.contextMenuListener = undefined
|
|
195
|
+
}
|
|
192
196
|
this.setMoveInputState(STATE.waitForInputStart)
|
|
193
197
|
break
|
|
194
198
|
|
|
195
199
|
default:
|
|
196
|
-
throw Error(`moveInputState ${newState}`)
|
|
200
|
+
throw Error(`260b09: moveInputState ${newState}`)
|
|
197
201
|
}
|
|
198
202
|
}
|
|
199
203
|
|
|
200
204
|
createDraggablePiece(pieceName) {
|
|
201
205
|
// maybe I should use the existing piece from the board and don't create a new one
|
|
202
206
|
if (this.draggablePiece) {
|
|
203
|
-
throw Error("
|
|
207
|
+
throw Error("59c195")
|
|
204
208
|
}
|
|
205
209
|
this.draggablePiece = Svg.createSvg(document.body)
|
|
206
210
|
this.draggablePiece.classList.add("cm-chessboard-draggable-piece")
|
|
@@ -268,7 +272,7 @@ export class VisualMoveInput {
|
|
|
268
272
|
const startPieceName = this.chessboard.getPiece(this.fromSquare)
|
|
269
273
|
const startPieceColor = startPieceName ? startPieceName.substring(0, 1) : undefined
|
|
270
274
|
if (color && startPieceColor === pieceColor) {
|
|
271
|
-
this.moveInputCanceledCallback(
|
|
275
|
+
this.moveInputCanceledCallback(this.fromSquare, square, MOVE_CANCELED_REASON.clickedAnotherPiece)
|
|
272
276
|
if (this.moveInputStartedCallback(square)) {
|
|
273
277
|
this.setMoveInputState(STATE.pieceClickedThreshold, {
|
|
274
278
|
square: square,
|
|
@@ -353,7 +357,7 @@ export class VisualMoveInput {
|
|
|
353
357
|
if (this.moveInputState === STATE.clickDragTo) {
|
|
354
358
|
this.chessboard.state.position.setPiece(this.fromSquare, this.movedPiece)
|
|
355
359
|
this.view.setPieceVisibility(this.fromSquare)
|
|
356
|
-
this.moveInputCanceledCallback(
|
|
360
|
+
this.moveInputCanceledCallback(square, null, MOVE_CANCELED_REASON.draggedBack)
|
|
357
361
|
this.setMoveInputState(STATE.reset)
|
|
358
362
|
} else {
|
|
359
363
|
this.setMoveInputState(STATE.clickTo, {square: square})
|
|
@@ -365,13 +369,13 @@ export class VisualMoveInput {
|
|
|
365
369
|
this.setMoveInputState(STATE.clickTo, {square: square})
|
|
366
370
|
} else if (this.moveInputState === STATE.secondClickThreshold) {
|
|
367
371
|
this.setMoveInputState(STATE.reset)
|
|
368
|
-
this.moveInputCanceledCallback(
|
|
372
|
+
this.moveInputCanceledCallback(square, null, MOVE_CANCELED_REASON.secondClick)
|
|
369
373
|
}
|
|
370
374
|
} else {
|
|
371
375
|
this.view.redrawPieces()
|
|
372
376
|
const moveStartSquare = this.fromSquare
|
|
373
377
|
this.setMoveInputState(STATE.reset)
|
|
374
|
-
this.moveInputCanceledCallback(
|
|
378
|
+
this.moveInputCanceledCallback(moveStartSquare, null, MOVE_CANCELED_REASON.movedOutOfBoard)
|
|
375
379
|
}
|
|
376
380
|
} else {
|
|
377
381
|
this.view.redrawPieces()
|
|
@@ -379,12 +383,15 @@ export class VisualMoveInput {
|
|
|
379
383
|
}
|
|
380
384
|
}
|
|
381
385
|
|
|
382
|
-
|
|
386
|
+
onContextMenu(e) { // while moving
|
|
387
|
+
e.preventDefault()
|
|
388
|
+
this.view.redrawPieces()
|
|
383
389
|
this.setMoveInputState(STATE.reset)
|
|
390
|
+
this.moveInputCanceledCallback(this.fromSquare, null, MOVE_CANCELED_REASON.secondaryClick)
|
|
384
391
|
}
|
|
385
392
|
|
|
386
393
|
destroy() {
|
|
387
|
-
this.reset
|
|
394
|
+
this.setMoveInputState(STATE.reset)
|
|
388
395
|
}
|
|
389
396
|
|
|
390
397
|
}
|