cm-chessboard 8.2.1 → 8.3.0

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 CHANGED
@@ -5,12 +5,7 @@ A JavaScript chessboard which is lightweight, ES6 module based, responsive, SVG
5
5
  cm-chessboard is the main chessboard of
6
6
  [chessmail.eu](https://www.chessmail.eu) and [chessmail.de](https://www.chessmail.de). It is also used
7
7
  in [chess-console](https://shaack.com/projekte/chess-console/examples/load-pgn.html) and in
8
- [cm-fen-editor](https://shaack.com/projekte/cm-fen-editor/). They are all nice written ES6 Modules to handle different
9
- aspects of chess games.
10
-
11
- > Note: With version 7, I made a heavy allover refactoring. The chessboard props have been changed and the files
12
- > structure also. Version 7 of the cm-chessboard will not work out of the box after an update from a previous version.
13
- > Also with version 7 comes the move cancelling via secondary mouse button.
8
+ [cm-fen-editor](https://shaack.com/projekte/cm-fen-editor/). They are all nice written ES6 Modules to handle different aspects of chess games.
14
9
 
15
10
  ## Features
16
11
 
@@ -18,24 +13,18 @@ aspects of chess games.
18
13
  - [Can handle moves input via click or drag](https://shaack.com/projekte/cm-chessboard/examples/validate-moves.html)
19
14
  - [Styleable via css and supports multiple piece sets](https://shaack.com/projekte/cm-chessboard/examples/different-styles.html)
20
15
  - Uses SVG for rendering
21
- - [Allows adding **extensions** to extend the
16
+ - [Allows adding extensions to extend the
22
17
  functionality](https://shaack.com/projekte/cm-chessboard/examples/extensions/arrows-extension.html)
23
18
 
24
19
  ## Extensions
25
20
 
26
- The core of cm-chessboard is small, fast and reduced to the essentials. You can extend its functionality with
27
- extensions.
21
+ The core of cm-chessboard is small, fast and reduced to the essentials. You can easily extend its functionality with extensions.
28
22
 
29
- - [Accessibility Extension](https://shaack.com/projekte/cm-chessboard/examples/extensions/accessibility-extension.html) -
30
- makes the chessboard more accessible
31
- - [Arrows Extension](https://shaack.com/projekte/cm-chessboard/examples/extensions/arrows-extension.html) - renders
32
- arrows on the chessboard
33
- - [Markers Extension](https://shaack.com/projekte/cm-chessboard/examples/extensions/markers-extension.html) 🆕 - create
34
- markers on specific squares
35
- - [PromotionDialog Extension](https://shaack.com/projekte/cm-chessboard/examples/extensions/promotion-dialog-extension.html)
36
- 🆕 - shows a dialog to select the piece to promote to
37
- - [RenderVideo Extension](https://shaack.com/projekte/cm-chessboard/examples/extensions/render-video-extension.html)
38
- 🆕 - renders a video from the pieces movement on the board
23
+ - [Markers Extension](https://shaack.com/projekte/cm-chessboard/examples/extensions/markers-extension.html) ⇨ create markers on specific squares
24
+ - [Arrows Extension](https://shaack.com/projekte/cm-chessboard/examples/extensions/arrows-extension.html) renders arrows on the chessboard
25
+ - [Accessibility Extension](https://shaack.com/projekte/cm-chessboard/examples/extensions/accessibility-extension.html) makes the chessboard more accessible
26
+ - [PromotionDialog Extension](https://shaack.com/projekte/cm-chessboard/examples/extensions/promotion-dialog-extension.html) ⇨ shows a dialog to select the piece to promote to
27
+ - [RenderVideo Extension](https://shaack.com/projekte/cm-chessboard/examples/extensions/render-video-extension.html) renders a video from the pieces movement on the board (beta version for now)
39
28
 
40
29
  ## Demo and repository
41
30
 
@@ -44,43 +33,92 @@ extensions.
44
33
 
45
34
  ![Example chessboards](https://shaack.com/projekte/assets/img/example_chessboards_staunty.png?v=2)
46
35
 
47
- ## Install
36
+ ## Installation and first steps
48
37
 
49
- **Option 1:** Install the [npm package](https://www.npmjs.com/package/cm-chessboard) with `npm install cm-chessboard`.
38
+ ### Step 1: Install the package
50
39
 
51
- **Option 2:** Download the code from [GitHub](https://github.com/shaack/cm-chessboard).
40
+ - **Option 1:** Install the [npm package](https://www.npmjs.com/package/cm-chessboard) with `npm install cm-chessboard`.
41
+ - **Option 2:** Download the code from [GitHub](https://github.com/shaack/cm-chessboard).
42
+ - **Option 3:** Use it via CDN https://cdn.jsdelivr.net/npm/cm-chessboard@8/src/Chessboard.js
52
43
 
53
- **Option 3:** Use it via CDN https://cdn.jsdelivr.net/npm/cm-chessboard@7/src/Chessboard.js
44
+ ### Step 2: Create your cm-chessboard page
54
45
 
55
- After installation, copy the sprite in `cm-chessboard/assets/images/` to your projects `assets/images/`
56
- folder. If you put the sprite somewhere else you have to configure the location
57
- with `{sprite.url: "./url/of/chessboard-sprite.svg"}`
58
- (see section 'Configuration' below).
46
+ #### Step 2a: Include the CSS file
59
47
 
60
- To run the unit tests in `/test` you first have to `npm install` the dev dependencies. Without tests there are no
61
- dependencies.
48
+ ```html
49
+ <link rel="stylesheet" href="./node_modules/cm-chessboard/assets/styles/cm-chessboard.css">
50
+ ```
62
51
 
63
- ## Usage
52
+ - Some extensions, like "[Markers](https://shaack.com/projekte/cm-chessboard/examples/extensions/markers-extension.html)", "[Promotion Dialog](https://shaack.com/projekte/cm-chessboard/examples/extensions/promotion-dialog-extension.html)" or "[Arrows](https://shaack.com/projekte/cm-chessboard/examples/extensions/arrows-extension.html)" need additional CSS. See the examples.
64
53
 
65
- Preconditions for using cm-chessboard in a web page:
54
+ #### Step 2b: Create a container for the chessboard
66
55
 
67
- 1. **include the css:** `assets/styles/cm-chessboard.css`
68
- 2. **import the ES6 module:** `import {Chessboard} from "PATH/TO/src/Chessboard.js"`
56
+ ```html
57
+ <div id="board"></div>
58
+ ```
69
59
 
70
- Example, showing a FEN:
60
+ #### Step 2c: Create the chessboard in your JavaScript code.
71
61
 
72
62
  ```html
73
-
74
63
  <script type="module">
75
64
  import {Chessboard} from "./src/Chessboard.js"
76
65
 
77
- new Chessboard(document.getElementById("containerId"),
78
- {position: "rn2k1r1/ppp1pp1p/3p2p1/5bn1/P7/2N2B2/1PPPPP2/2BNK1RR"})
66
+ const board = new Chessboard(document.getElementById("board"), {
67
+ position: FEN.start,
68
+ assetsUrl: "./node_modules/cm-chessboard/assets/" // or wherever you copied the assets folder to
69
+ })
79
70
  </script>
80
71
  ```
81
72
 
82
- Take a look at the [/examples](https://github.com/shaack/cm-chessboard/tree/master/examples) folder for more simple
83
- examples.
73
+ You need to configure the `assetsUrl` in your chessboard props (the second parameter). The `assetsUrl` must be the path to the `assets` folder of this project, where the pieces SVGs and other resources are located.
74
+
75
+ You can also copy the `assets` folder from `cm-chessboard/assets` to your project and modify the content.
76
+
77
+ #### See also
78
+
79
+ - [Simple cm-chessboard example online](https://shaack.com/projekte/cm-chessboard/examples/simple-boards.html)
80
+
81
+ ### Step 3: (Optional) Enable user input
82
+
83
+ To enable the user to move the pieces, you have to enable the move input.
84
+
85
+ ```javascript
86
+ const board = new Chessboard(document.getElementById("board"), {
87
+ position: FEN.start,
88
+ assetsUrl: "../assets/",
89
+ extensions: [{class: Markers}] // Looks better with markers
90
+ })
91
+
92
+ board.enableMoveInput(inputHandler) // This enables the move input
93
+
94
+ function inputHandler(event) {
95
+ console.log(event)
96
+ switch (event.type) {
97
+ case INPUT_EVENT_TYPE.moveInputStarted:
98
+ log(`moveInputStarted: ${event.squareFrom}`)
99
+ return true // false cancels move
100
+ case INPUT_EVENT_TYPE.validateMoveInput:
101
+ log(`validateMoveInput: ${event.squareFrom}-${event.squareTo}`)
102
+ return true // false cancels move
103
+ case INPUT_EVENT_TYPE.moveInputCanceled:
104
+ log(`moveInputCanceled`)
105
+ break
106
+ case INPUT_EVENT_TYPE.moveInputFinished:
107
+ log(`moveInputFinished`)
108
+ break
109
+ case INPUT_EVENT_TYPE.movingOverSquare:
110
+ log(`movingOverSquare: ${event.square}`)
111
+ break
112
+ }
113
+ }
114
+ ```
115
+
116
+ #### See also
117
+
118
+ - [Simple example with move input enabled](https://shaack.com/projekte/cm-chessboard/examples/enable-input.html)
119
+ - [More complex example with move validation](https://shaack.com/projekte/cm-chessboard/examples/validate-moves.html)
120
+
121
+ Take a look at the [/examples](https://github.com/shaack/cm-chessboard/tree/master/examples) folder for more examples.
84
122
 
85
123
  ## Configuration
86
124
 
@@ -91,9 +129,8 @@ this.props = {
91
129
  position: FEN.empty, // set position as fen, use FEN.start or FEN.empty as shortcuts
92
130
  orientation: COLOR.white, // white on bottom
93
131
  responsive: true, // resize the board automatically to the size of the context element
94
- language: navigator.language.substring(0, 2).toLowerCase(), // supports "de" and "en" for now, used for pieces naming
95
132
  assetsUrl: "./assets/", // put all css and sprites in this folder, will be ignored for absolute urls of assets files
96
- assetsCache: true, // cache sprites
133
+ assetsCache: true, // cache the sprites, deactivate if you want to use multiple pieces sets in one page
97
134
  style: {
98
135
  cssClass: "default", // set the css theme of the board, try "green", "blue" or "chess-club"
99
136
  showCoordinates: true, // show ranks and files
@@ -146,44 +183,6 @@ Sets the position as `fen` or only the position part of a `fen`. Returns a **Pro
146
183
 
147
184
  Returns the board position in form of the position part of a `fen`.
148
185
 
149
- ### addMarker(type, square)
150
-
151
- > Moved to the Markers extension with version 6
152
-
153
- Adds a marker on a square.
154
-
155
- Default types are: `MARKER_TYPE.frame`, `MARKER_TYPE.square`, `MARKER_TYPE.dot`, `MARKER_TYPE.circle` exportet
156
- by `Chessboard.js`.
157
-
158
- #### You can create your own marker types:
159
-
160
- Just create an object like `const myMarker = {class: "markerCssClass", slice: "markerSliceId"}`, where `class` is the
161
- css class of the marker for styling
162
- and `slice` is the `id` in `sprite.svg`. See also [Create your own custom markers](#create-your-own-custom-markers)
163
- below.
164
-
165
- [Example for **addMarker**, **getMarkers** and
166
- **removeMarkers**](https://shaack.com/projekte/cm-chessboard/examples/extensions/markers-extension.html)
167
-
168
- ### getMarkers(type = undefined, square = undefined)
169
-
170
- > Moved to the Markers extension with version 6
171
-
172
- Returns the board's markers as an array.
173
-
174
- Only set type, to get all markers of a type on the board. Set type to `undefined`, to get markers of all types on a
175
- square.
176
- Set `both` to `undefined` to get all markers on the board.
177
-
178
- ### removeMarkers(type = undefined, square = undefined)
179
-
180
- > Moved to the Markers extension with version 6
181
-
182
- Removes markers from the board.
183
-
184
- Only set `type` to remove all markers of `type` from the board. Set `type` to `undefined`, to remove all types
185
- of markers from a square. Call without parameters to remove all markers from the board.
186
-
187
186
  ### setOrientation(color)
188
187
 
189
188
  Sets the board orientation (color at bottom). Allowed values are `COLOR.white` or `COLOR.black`.
@@ -254,70 +253,7 @@ chessboard-sprite-staunty.svg) and a sprite of the
254
253
  (chessboard-sprite.svg).
255
254
 
256
255
  Sprites must be 40x40px in size where the piece elements must have ids like
257
- "bp" (black pawn) or "wq" (white queen). Just open the sprite in a text editor, SVG is readable like HTML. Also the
258
- markers are defined in the sprite.
259
-
260
- ## Create your own custom markers
261
-
262
- The ability to add custom markers is build in. You can use the existing
263
- marker shapes in the SVG sprite and create your own markers with just css or create
264
- your own custom SVG shapes. With a program like InkScape or Sketch this should be relatively easy.
265
-
266
- Example: The markerCircle is defined in the SVG like this.
267
-
268
- ```svg
269
-
270
- <g id="markerCircle" transform="translate(2.000000, 2.000000)" fill="#000000" fill-opacity="0">
271
- <circle cx="18" cy="18" r="18"/>
272
- </g>
273
- ```
274
-
275
- It's a circle with the radius 18 and its center at 20/20.
276
-
277
- Important is the id "markerCircle". You can set the marker
278
- with `board.addMarker({class: "markerSquare", slice: "markerSquare"}, "e4")`
279
- "emphasize" is the css class, which defines the color and opacity of the marker. "slice" is the id of the marker in the
280
- SVG. This is
281
- also demonstrated in
282
- the [mark squares example](https://shaack.com/projekte/cm-chessboard/examples/extensions/markers-extension.html)
283
- .
284
-
285
- The color and stroke-width of the marker is defined in the css (or scss). You could also define your marker completely
286
- in the sprite, but then that is not so flexible.
287
-
288
- These are the css styles of the markers "markerSquare" and "markerCircleRed".
289
-
290
- ```css
291
- marker.marker-square {
292
- fill: black;
293
- opacity: 0.11;
294
- }
295
-
296
- marker.marker-circle-red {
297
- stroke: #aa0000;
298
- stroke-width: 3px;
299
- opacity: 0.4;
300
- }
301
- ```
302
-
303
- So you can simply add a marker with the id `myMarkerIdInSvg` to the SVG, and add the class `myMarkerCssClass` to the
304
- css. Then you can show it on the field "e4" with
305
-
306
- `addMarker({class: "myMarkerCssClass", slice: "myMarkerIdInSvg"}, "e4")`
307
-
308
- To allow easy removing of the marker, you have to define the marker type in your code.
309
-
310
- ```js
311
- const myMarkerType = {class: "myMarkerCssClass", slice: "myMarkerIdInSvg"}
312
- // add
313
- chessboard.addMarker(myMarkerType, "e4")
314
- // remove a specific marker
315
- chessboard.removeMarkers(myMarkerType, "e4")
316
- // remove all "myMarkerType"
317
- chessboard.removeMarkers(myMarkerType)
318
- // remove all markers
319
- chessboard.removeMarkers()
320
- ```
256
+ "bp" (black pawn) or "wq" (white queen). Just open the sprite in a text editor, SVG is readable like HTML.
321
257
 
322
258
  ## Extensions
323
259
 
@@ -369,32 +305,52 @@ const chessboard = new Chessboard(document.getElementById("board"), {
369
305
  })
370
306
  ```
371
307
 
372
- ### registerMethod(name, callback)
373
-
374
- > Deprecated 2023-05-18, just add methods directly to the chessboard class instance.
308
+ ### Add methods to the chessboard
375
309
 
376
- Add methods to the main chessboard from your extension with `this.registerMethod("name", callback)`
377
- like `addArrow(type, from, to)` in the
378
- [Arrows extension](https://shaack.com/projekte/cm-chessboard/examples/extensions/arrows-extension.html).
310
+ Add methods to the chessboard in the constructor of your extension like shown below.
379
311
 
380
312
  ```js
381
- this.registerMethod("addArrow", this.addArrow)
313
+ chessboard.addMarker = this.addMarker.bind(this)
382
314
  ```
383
315
 
384
- ### Existing extensions
316
+ ## The main extensions contained in cm-chessboard
385
317
 
386
- cm-chessboard is shipped with these extensions.
318
+ ### Markers extension
387
319
 
388
- #### Accessibility Extension
320
+ Creates markers on the board. Example: [Markers extension](https://shaack.com/projekte/cm-chessboard/examples/extensions/markers-extension.html)
321
+
322
+ See the [README](src/extensions/markers/README.md) of the Markers. extension.
323
+
324
+ ### Arrows extension
325
+
326
+ Draw arrows on the board. Example: [Arrows extension](https://shaack.com/projekte/cm-chessboard/examples/extensions/arrows-extension.html)
327
+
328
+ #### Methods
329
+
330
+ ##### addArrow(type, fromSquare, toSquare)
331
+
332
+ Add an arrow.
333
+
334
+ ##### removeArrows(type, from, to)
335
+
336
+ To remove all arrows, call `chessboard.removeArrows()` without parameters. To remove all arrows of a specific
337
+ type (type "danger"), call `chessboard.removeArrows(ARROW_TYPE.danger)`. To remove all arrows starting at "
338
+ e2"
339
+ you can call `chessboard.removeArrows(undefined, "e2")` and so on...
340
+
341
+ ##### getArrows(type, from, to)
342
+
343
+ To get all arrows, call `chessboard.getArrows()` without parameters, as with `removeArrows(type, from, to)`.
344
+
345
+ ### Accessibility Extension
389
346
 
390
347
  This extension ensures that visual impaired people can better use the chessboard. It displays the braille notation
391
348
  of the current position in the alt tag of the board image and enables a form to move the pieces via text input. It
392
349
  can also display the board as HTML table and the pieces as list.
393
350
 
394
- See
395
- example [Accessibility extension](https://shaack.com/projekte/cm-chessboard/examples/extensions/accessibility-extension.html)
351
+ See the example [Accessibility extension](https://shaack.com/projekte/cm-chessboard/examples/extensions/accessibility-extension.html)
396
352
 
397
- ##### Usage
353
+ #### Usage
398
354
 
399
355
  ```js
400
356
  const chessboard = new Chessboard(document.getElementById("board"), {
@@ -419,28 +375,6 @@ const chessboard = new Chessboard(document.getElementById("board"), {
419
375
  })
420
376
  ```
421
377
 
422
- #### Arrows extension
423
-
424
- Draw arrows on the board.
425
-
426
- Example: [Arrows extension](https://shaack.com/projekte/cm-chessboard/examples/extensions/arrows-extension.html)
427
-
428
- ##### Methods
429
-
430
- ###### addArrow(type, fromSquare, toSquare)
431
-
432
- Add an arrow.
433
-
434
- ###### removeArrows(type, from, to)
435
-
436
- To remove all arrows, call `chessboard.removeArrows()` without parameters. To remove all arrows of a specific
437
- type (type "danger"), call `chessboard.removeArrows(ARROW_TYPE.danger)`. To remove all arrows starting at "
438
- e2"
439
- you can call `chessboard.removeArrows(undefined, "e2")` and so on...
440
-
441
- ###### getArrows(type, from, to)
442
-
443
- To get all arrows, call `chessboard.getArrows()` without parameters, as with `removeArrows(type, from, to)`.
444
378
 
445
379
  ## Usage with JS Frameworks
446
380
 
@@ -11,7 +11,7 @@
11
11
  <body>
12
12
  <h1><a href="../../">cm-chessboard</a></h1>
13
13
  <h2>Example: Markers Extension with pointer input</h2>
14
- <p>The second board shows the usage of autoMarkers, when moving a piece.</p>
14
+ <p>Use left and right click to create markers on the boards. The second board shows the usage of autoMarkers, when moving a piece.</p>
15
15
  <div class="board" id="board1"></div>
16
16
  <div class="board" id="board2"></div>
17
17
  <div style="clear: both"></div>
@@ -15,9 +15,11 @@
15
15
  <br style="clear: both"/>
16
16
  <pre>
17
17
  new Chessboard(document.getElementById("board1"), {
18
+ assetsUrl: "../assets/",
18
19
  position: FEN.start
19
20
  })
20
21
  new Chessboard(document.getElementById("board2"), {
22
+ assetsUrl: "../assets/",
21
23
  position: "rn2k1r1/ppp1pp1p/3p2p1/5bn1/P7/2N2B2/1PPPPP2/2BNK1RR w Gkq - 4 11",
22
24
  style: {pieces: {file: "pieces/staunty.svg"},cssClass: "green", borderType: BORDER_TYPE.frame},
23
25
  orientation: COLOR.black
@@ -28,13 +30,13 @@ new Chessboard(document.getElementById("board2"), {
28
30
  import {FEN} from "../src/model/Position.js"
29
31
 
30
32
  new Chessboard(document.getElementById("board1"), {
31
- position: FEN.start,
32
- assetsUrl: "../assets/"
33
+ assetsUrl: "../assets/",
34
+ position: FEN.start
33
35
  })
34
36
  new Chessboard(document.getElementById("board2"), {
35
- position: "rn2k1r1/ppp1pp1p/3p2p1/5bn1/P7/2N2B2/1PPPPP2/2BNK1RR w Gkq - 4 11",
36
37
  assetsUrl: "../assets/",
37
38
  assetsCache: false,
39
+ position: "rn2k1r1/ppp1pp1p/3p2p1/5bn1/P7/2N2B2/1PPPPP2/2BNK1RR w Gkq - 4 11",
38
40
  style: {pieces: {file: "pieces/staunty.svg"},cssClass: "green", borderType: BORDER_TYPE.frame},
39
41
  orientation: COLOR.black
40
42
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cm-chessboard",
3
- "version": "8.2.1",
3
+ "version": "8.3.0",
4
4
  "description": "A JavaScript chessboard which is lightweight, ES6 module based, responsive, SVG rendered and without dependencies.",
5
5
  "keywords": [
6
6
  "chess",
package/src/Chessboard.js CHANGED
@@ -56,9 +56,8 @@ export class Chessboard {
56
56
  position: FEN.empty, // set position as fen, use FEN.start or FEN.empty as shortcuts
57
57
  orientation: COLOR.white, // white on bottom
58
58
  responsive: true, // resize the board automatically to the size of the context element
59
- language: navigator.language.substring(0, 2).toLowerCase(), // supports "de" and "en" for now, used for pieces naming
60
59
  assetsUrl: "./assets/", // put all css and sprites in this folder, will be ignored for absolute urls of assets files
61
- assetsCache: true, // cache sprites
60
+ assetsCache: true, // cache the sprites, deactivate if you want to use multiple pieces sets in one page
62
61
  style: {
63
62
  cssClass: "default", // set the css theme of the board, try "green", "blue" or "chess-club"
64
63
  showCoordinates: true, // show ranks and files
@@ -74,9 +73,6 @@ export class Chessboard {
74
73
  extensions: [ /* {class: ExtensionClass, props: { ... }} */] // add extensions here
75
74
  }
76
75
  Utils.mergeObjects(this.props, props)
77
- if (this.props.language !== "de" && this.props.language !== "en") {
78
- this.props.language = "en"
79
- }
80
76
  this.state = new ChessboardState()
81
77
  this.view = new ChessboardView(this)
82
78
  this.positionAnimationsQueue = new PositionAnimationsQueue(this)
@@ -5,7 +5,7 @@
5
5
  */
6
6
  import {Extension, EXTENSION_POINT} from "../../model/Extension.js"
7
7
  import {COLOR, INPUT_EVENT_TYPE} from "../../Chessboard.js"
8
- import {piecesTranslations, renderPieceTitle} from "../../lib/I18n.js"
8
+ import {piecesTranslations, renderPieceTitle} from "./I18n.js"
9
9
  import {Utils} from "../../lib/Utils.js"
10
10
 
11
11
  const translations = {
@@ -41,6 +41,7 @@ export class Accessibility extends Extension {
41
41
  constructor(chessboard, props) {
42
42
  super(chessboard)
43
43
  this.props = {
44
+ language: navigator.language.substring(0, 2).toLowerCase(), // supports "de" and "en" for now, used for pieces naming
44
45
  brailleNotationInAlt: true, // show the braille notation of the position in the alt attribute of the SVG image
45
46
  movePieceForm: true, // display a form to move a piece (from, to, move)
46
47
  boardAsTable: true, // display the board additionally as HTML table
@@ -48,7 +49,10 @@ export class Accessibility extends Extension {
48
49
  visuallyHidden: true // hide all those extra outputs visually but keep them accessible for screen readers and braille displays
49
50
  }
50
51
  Object.assign(this.props, props)
51
- this.lang = chessboard.props.language
52
+ if (this.props.language !== "de" && this.props.language !== "en") {
53
+ this.props.language = "en"
54
+ }
55
+ this.lang = this.props.language
52
56
  this.tPieces = piecesTranslations[this.lang]
53
57
  this.t = translations[this.lang]
54
58
  this.components = []
@@ -0,0 +1,97 @@
1
+ # cm-chessboard Markers extension
2
+
3
+ ## API
4
+
5
+ ### addMarker(type, square)
6
+
7
+ Adds a marker on a square.
8
+
9
+ Default types are: `MARKER_TYPE.frame`, `MARKER_TYPE.square`, `MARKER_TYPE.dot`, `MARKER_TYPE.circle` exportet
10
+ by `Chessboard.js`.
11
+
12
+ #### You can create your own marker types:
13
+
14
+ Just create an object like `const myMarker = {class: "markerCssClass", slice: "markerSliceId"}`, where `class` is the
15
+ css class of the marker for styling
16
+ and `slice` is the `id` in `sprite.svg`. See also [Create your own custom markers](#create-your-own-custom-markers)
17
+ below.
18
+
19
+ [Example for **addMarker**, **getMarkers** and
20
+ **removeMarkers**](https://shaack.com/projekte/cm-chessboard/examples/extensions/markers-extension.html)
21
+
22
+ ### getMarkers(type = undefined, square = undefined)
23
+
24
+ Returns the board's markers as an array.
25
+
26
+ Only set type, to get all markers of a type on the board. Set type to `undefined`, to get markers of all types on a
27
+ square.
28
+ Set `both` to `undefined` to get all markers on the board.
29
+
30
+ ### removeMarkers(type = undefined, square = undefined)
31
+
32
+ Removes markers from the board.
33
+
34
+ Only set `type` to remove all markers of `type` from the board. Set `type` to `undefined`, to remove all types
35
+ of markers from a square. Call without parameters to remove all markers from the board.
36
+
37
+ ## Create your own custom markers
38
+
39
+ The ability to add custom markers is build in. You can use the existing
40
+ marker shapes in the SVG sprite and create your own markers with just css or create
41
+ your own custom SVG shapes. With a program like InkScape or Sketch this should be relatively easy.
42
+
43
+ Example: The markerCircle is defined in the SVG like this.
44
+
45
+ ```svg
46
+
47
+ <g id="markerCircle" transform="translate(2.000000, 2.000000)" fill="#000000" fill-opacity="0">
48
+ <circle cx="18" cy="18" r="18"/>
49
+ </g>
50
+ ```
51
+
52
+ It's a circle with the radius 18 and its center at 20/20.
53
+
54
+ Important is the id "markerCircle". You can set the marker
55
+ with `board.addMarker({class: "markerSquare", slice: "markerSquare"}, "e4")`
56
+ "emphasize" is the css class, which defines the color and opacity of the marker. "slice" is the id of the marker in the
57
+ SVG. This is
58
+ also demonstrated in
59
+ the [mark squares example](https://shaack.com/projekte/cm-chessboard/examples/extensions/markers-extension.html)
60
+ .
61
+
62
+ The color and stroke-width of the marker is defined in the css (or scss). You could also define your marker completely
63
+ in the sprite, but then that is not so flexible.
64
+
65
+ These are the css styles of the markers "markerSquare" and "markerCircleRed".
66
+
67
+ ```css
68
+ marker.marker-square {
69
+ fill: black;
70
+ opacity: 0.11;
71
+ }
72
+
73
+ marker.marker-circle-red {
74
+ stroke: #aa0000;
75
+ stroke-width: 3px;
76
+ opacity: 0.4;
77
+ }
78
+ ```
79
+
80
+ So you can simply add a marker with the id `myMarkerIdInSvg` to the SVG, and add the class `myMarkerCssClass` to the
81
+ css. Then you can show it on the field "e4" with
82
+
83
+ `addMarker({class: "myMarkerCssClass", slice: "myMarkerIdInSvg"}, "e4")`
84
+
85
+ To allow easy removing of the marker, you have to define the marker type in your code.
86
+
87
+ ```js
88
+ const myMarkerType = {class: "myMarkerCssClass", slice: "myMarkerIdInSvg"}
89
+ // add
90
+ chessboard.addMarker(myMarkerType, "e4")
91
+ // remove a specific marker
92
+ chessboard.removeMarkers(myMarkerType, "e4")
93
+ // remove all "myMarkerType"
94
+ chessboard.removeMarkers(myMarkerType)
95
+ // remove all markers
96
+ chessboard.removeMarkers()
97
+ ```
File without changes