cm-chessboard 8.1.4 → 8.2.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.
@@ -23,7 +23,7 @@ new Chessboard(document.getElementById("board"), {
23
23
  extensions: [{class: AutoBorderNone}]
24
24
  })
25
25
  </pre>
26
- <p>Also uses the "AutoBorderNone" extension to switch off the frame border below 560px width.</p>
26
+ <p>This example also uses the "AutoBorderNone" extension, which switches off the frame border on smaller boards.</p>
27
27
  <script type="module">
28
28
  import {BORDER_TYPE, Chessboard} from "../src/Chessboard.js"
29
29
  import {FEN} from "../src/model/Position.js"
@@ -32,6 +32,7 @@ new Chessboard(document.getElementById("board"), {
32
32
  new Chessboard(document.getElementById("board"), {
33
33
  position: FEN.start,
34
34
  assetsUrl: "../assets/",
35
+ debug: true,
35
36
  style: {
36
37
  aspectRatio: 0.9,
37
38
  pieces: {file: "pieces/staunty.svg"},
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cm-chessboard",
3
- "version": "8.1.4",
3
+ "version": "8.2.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
@@ -89,7 +89,7 @@ export class Chessboard {
89
89
  this.state.position = new Position(this.props.position)
90
90
  this.view.redrawPieces()
91
91
  this.state.invokeExtensionPoints(EXTENSION_POINT.positionChanged)
92
- this.initialized = Promise.resolve()
92
+ this.initialized = Promise.resolve() // deprecated 2023-09-19 don't use this anymore
93
93
  }
94
94
 
95
95
  // API //
@@ -10,16 +10,21 @@ export class AutoBorderNone extends Extension {
10
10
  super(chessboard)
11
11
  this.props = {
12
12
  chessboardBorderType: chessboard.props.style.borderType,
13
- borderNoneBelow: 550 // pixels width of the board, where the border is set to none
13
+ borderNoneBelow: 540 // pixels width of the board, where the border is set to none
14
14
  }
15
15
  Object.assign(this.props, props)
16
16
  this.registerExtensionPoint(EXTENSION_POINT.beforeRedrawBoard, this.extensionPointBeforeRedrawBoard.bind(this))
17
17
  }
18
18
  extensionPointBeforeRedrawBoard() {
19
+ let newBorderType
19
20
  if(this.chessboard.view.width < this.props.borderNoneBelow){
20
- this.chessboard.props.style.borderType = "none"
21
+ newBorderType = "none"
21
22
  } else {
22
- this.chessboard.props.style.borderType = this.props.chessboardBorderType
23
+ newBorderType = this.props.chessboardBorderType
24
+ }
25
+ if(newBorderType !== this.chessboard.props.style.borderType) {
26
+ this.chessboard.props.style.borderType = newBorderType
27
+ this.chessboard.view.updateMetrics()
23
28
  }
24
29
  }
25
30
  }
@@ -11,9 +11,7 @@ export class Persistence extends Extension {
11
11
  console.warn("The Persistence extension is work in progress, don't use it in production.")
12
12
  this.props = props
13
13
  this.registerExtensionPoint(EXTENSION_POINT.positionChanged, this.savePosition.bind(this))
14
- chessboard.initialized.then(() => {
15
- this.loadPosition()
16
- })
14
+ this.loadPosition()
17
15
  }
18
16
 
19
17
  savePosition() {
@@ -28,4 +26,4 @@ export class Persistence extends Extension {
28
26
  this.chessboard.setPosition(this.props.initialPosition)
29
27
  }
30
28
  }
31
- }
29
+ }
@@ -36,11 +36,7 @@ export class ChessboardView {
36
36
  this.pointerDownListener = this.pointerDownHandler.bind(this)
37
37
  this.container.addEventListener("mousedown", this.pointerDownListener)
38
38
  this.container.addEventListener("touchstart", this.pointerDownListener, {passive: false})
39
-
40
39
  this.createSvgAndGroups()
41
- // this.updateMetrics()
42
- this.handleResize()
43
- // this.redrawBoard()
44
40
  }
45
41
 
46
42
  pointerDownHandler(e) {