cm-chessboard 8.0.1 → 8.0.3

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.
@@ -25,10 +25,15 @@
25
25
 
26
26
  const chess = new Chess()
27
27
 
28
+ let seed = 71;
29
+ function random() {
30
+ const x = Math.sin(seed++) * 10000;
31
+ return x - Math.floor(x);
32
+ }
28
33
  function makeEngineMove(chessboard) {
29
34
  const possibleMoves = chess.moves({verbose: true})
30
35
  if (possibleMoves.length > 0) {
31
- const randomIndex = Math.floor(Math.random() * possibleMoves.length)
36
+ const randomIndex = Math.floor(random() * possibleMoves.length)
32
37
  const randomMove = possibleMoves[randomIndex]
33
38
  setTimeout(() => { // smoother with 500ms delay
34
39
  chess.move({from: randomMove.from, to: randomMove.to})
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cm-chessboard",
3
- "version": "8.0.1",
3
+ "version": "8.0.3",
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
@@ -46,7 +46,6 @@ export {FEN}
46
46
  export class Chessboard {
47
47
 
48
48
  constructor(context, props = {}) {
49
- this.initialized = Promise.resolve()
50
49
  if (!context) {
51
50
  throw new Error("container element is " + context)
52
51
  }
@@ -18,8 +18,8 @@ export class ChessboardView {
18
18
  if (chessboard.props.assetsCache) {
19
19
  this.cacheSpriteToDiv("cm-chessboard-sprite", this.getSpriteUrl())
20
20
  }
21
- this.context = document.createElement("div")
22
- this.chessboard.context.appendChild(this.context)
21
+ this.container = document.createElement("div")
22
+ this.chessboard.context.appendChild(this.container)
23
23
  if (chessboard.props.responsive) {
24
24
  if (typeof ResizeObserver !== "undefined") {
25
25
  this.resizeObserver = new ResizeObserver(() => {
@@ -34,8 +34,8 @@ export class ChessboardView {
34
34
  this.positionsAnimationTask = Promise.resolve()
35
35
  this.pointerDownListener = this.pointerDownHandler.bind(this)
36
36
  this.pointerDownListener = this.pointerDownHandler.bind(this)
37
- this.context.addEventListener("mousedown", this.pointerDownListener)
38
- this.context.addEventListener("touchstart", this.pointerDownListener, {passive: false})
37
+ this.container.addEventListener("mousedown", this.pointerDownListener)
38
+ this.container.addEventListener("touchstart", this.pointerDownListener, {passive: false})
39
39
 
40
40
  this.createSvgAndGroups()
41
41
  this.updateMetrics()
@@ -80,7 +80,7 @@ export class ChessboardView {
80
80
  }
81
81
 
82
82
  createSvgAndGroups() {
83
- this.svg = Svg.createSvg(this.context)
83
+ this.svg = Svg.createSvg(this.container)
84
84
  // let description = document.createElement("description")
85
85
  // description.innerText = "Chessboard"
86
86
  // description.id = "svg-description"
@@ -101,8 +101,8 @@ export class ChessboardView {
101
101
 
102
102
  updateMetrics() {
103
103
  const piecesTileSize = this.chessboard.props.style.pieces.tileSize
104
- this.width = this.context.clientWidth
105
- this.height = this.context.clientWidth * (this.chessboard.props.style.aspectRatio || 1)
104
+ this.width = this.container.clientWidth
105
+ this.height = this.container.clientWidth * (this.chessboard.props.style.aspectRatio || 1)
106
106
  if (this.chessboard.props.style.borderType === BORDER_TYPE.frame) {
107
107
  this.borderSize = this.width / 25
108
108
  } else if (this.chessboard.props.style.borderType === BORDER_TYPE.thin) {
@@ -120,9 +120,9 @@ export class ChessboardView {
120
120
  }
121
121
 
122
122
  handleResize() {
123
- this.context.style.width = this.chessboard.context.clientWidth + "px"
124
- this.context.style.height = (this.chessboard.context.clientWidth * this.chessboard.props.style.aspectRatio) + "px"
125
- if (this.context.clientWidth !== this.width || this.context.clientHeight !== this.height) {
123
+ this.container.style.width = this.chessboard.context.clientWidth + "px"
124
+ this.container.style.height = (this.chessboard.context.clientWidth * this.chessboard.props.style.aspectRatio) + "px"
125
+ if (this.container.clientWidth !== this.width || this.container.clientHeight !== this.height) {
126
126
  this.updateMetrics()
127
127
  this.redrawBoard()
128
128
  this.redrawPieces()
@@ -242,10 +242,6 @@ export class VisualMoveInput {
242
242
  if (!(e.type === "mousedown" && e.button === 0 || e.type === "touchstart")) {
243
243
  return
244
244
  }
245
- if(e.type === "mousedown") { // another try to prevent strange safari desktop select all bug
246
- e.preventDefault()
247
- e.stopPropagation()
248
- }
249
245
  const square = e.target.getAttribute("data-square")
250
246
  if (!square) { // pointer on square
251
247
  return
@@ -317,8 +313,6 @@ export class VisualMoveInput {
317
313
  pageX = e.pageX
318
314
  pageY = e.pageY
319
315
  target = e.target
320
- e.preventDefault() // trying to prevent strange safari desktop bug, selecting the whole page on drag
321
- e.stopPropagation()
322
316
  } else if (e.type === "touchmove") {
323
317
  clientX = e.touches[0].clientX
324
318
  clientY = e.touches[0].clientY
package/test/TestBoard.js CHANGED
@@ -24,7 +24,7 @@ describe("TestBoard", () => {
24
24
  assetsUrl: "../assets/",
25
25
  position: FEN.start
26
26
  })
27
- assert.equal(chessboard.view.context.childNodes.length, 1)
27
+ assert.equal(chessboard.view.container.childNodes.length, 1)
28
28
  chessboard.destroy()
29
29
  assert.equal(chessboard.state, undefined)
30
30
  })