cm-chessboard 3.17.9 → 3.18.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cm-chessboard",
3
- "version": "3.17.9",
3
+ "version": "3.18.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",
@@ -45,7 +45,7 @@ export class Chessboard {
45
45
  if (!context) {
46
46
  throw new Error("container element is " + context)
47
47
  }
48
- this.element = context
48
+ this.context = context
49
49
  this.id = (Math.random() + 1).toString(36).substr(2, 6)
50
50
  let defaultProps = {
51
51
  position: "empty", // set as fen, "start" or "empty"
@@ -79,7 +79,7 @@ export class Chessboard {
79
79
  Object.assign(this.props.style, props.style)
80
80
  }
81
81
  if (this.props.style.aspectRatio) {
82
- this.element.style.height = (this.element.offsetWidth * this.props.style.aspectRatio) + "px"
82
+ this.context.style.height = (this.context.offsetWidth * this.props.style.aspectRatio) + "px"
83
83
  }
84
84
  this.state = new ChessboardState()
85
85
  if (this.props.position === "start") {
@@ -199,9 +199,9 @@ export class Chessboard {
199
199
  this.view = undefined
200
200
  this.state = undefined
201
201
  if (this.squareSelectListener) {
202
- this.element.removeEventListener("contextmenu", this.squareSelectListener)
203
- this.element.removeEventListener("mouseup", this.squareSelectListener)
204
- this.element.removeEventListener("touchend", this.squareSelectListener)
202
+ this.context.removeEventListener("contextmenu", this.squareSelectListener)
203
+ this.context.removeEventListener("mouseup", this.squareSelectListener)
204
+ this.context.removeEventListener("touchend", this.squareSelectListener)
205
205
  }
206
206
  }
207
207
 
@@ -248,17 +248,17 @@ export class Chessboard {
248
248
  square: SQUARE_COORDINATES[index]
249
249
  })
250
250
  }
251
- this.element.addEventListener("contextmenu", this.squareSelectListener)
252
- this.element.addEventListener("mouseup", this.squareSelectListener)
253
- this.element.addEventListener("touchend", this.squareSelectListener)
251
+ this.context.addEventListener("contextmenu", this.squareSelectListener)
252
+ this.context.addEventListener("mouseup", this.squareSelectListener)
253
+ this.context.addEventListener("touchend", this.squareSelectListener)
254
254
  this.state.squareSelectEnabled = true
255
255
  this.view.visualizeInputState()
256
256
  }
257
257
 
258
258
  disableSquareSelect() {
259
- this.element.removeEventListener("contextmenu", this.squareSelectListener)
260
- this.element.removeEventListener("mouseup", this.squareSelectListener)
261
- this.element.removeEventListener("touchend", this.squareSelectListener)
259
+ this.context.removeEventListener("contextmenu", this.squareSelectListener)
260
+ this.context.removeEventListener("mouseup", this.squareSelectListener)
261
+ this.context.removeEventListener("touchend", this.squareSelectListener)
262
262
  this.squareSelectListener = undefined
263
263
  this.state.squareSelectEnabled = false
264
264
  this.view.visualizeInputState()
@@ -80,7 +80,7 @@ export class ChessboardView {
80
80
  this.resizeObserver = new ResizeObserver(() => {
81
81
  this.handleResize()
82
82
  })
83
- this.resizeObserver.observe(this.chessboard.element)
83
+ this.resizeObserver.observe(this.chessboard.context)
84
84
  } else {
85
85
  this.resizeListener = this.handleResize.bind(this)
86
86
  window.addEventListener("resize", this.resizeListener)
@@ -88,8 +88,8 @@ export class ChessboardView {
88
88
  }
89
89
 
90
90
  this.pointerDownListener = this.pointerDownHandler.bind(this)
91
- this.chessboard.element.addEventListener("mousedown", this.pointerDownListener)
92
- this.chessboard.element.addEventListener("touchstart", this.pointerDownListener)
91
+ this.chessboard.context.addEventListener("mousedown", this.pointerDownListener)
92
+ this.chessboard.context.addEventListener("touchstart", this.pointerDownListener)
93
93
 
94
94
  this.createSvgAndGroups()
95
95
  this.updateMetrics()
@@ -106,13 +106,13 @@ export class ChessboardView {
106
106
  destroy() {
107
107
  this.moveInput.destroy()
108
108
  if (this.resizeObserver) {
109
- this.resizeObserver.unobserve(this.chessboard.element)
109
+ this.resizeObserver.unobserve(this.chessboard.context)
110
110
  }
111
111
  if (this.resizeListener) {
112
112
  window.removeEventListener("resize", this.resizeListener)
113
113
  }
114
- this.chessboard.element.removeEventListener("mousedown", this.pointerDownListener)
115
- this.chessboard.element.removeEventListener("touchstart", this.pointerDownListener)
114
+ this.chessboard.context.removeEventListener("mousedown", this.pointerDownListener)
115
+ this.chessboard.context.removeEventListener("touchstart", this.pointerDownListener)
116
116
  Svg.removeElement(this.svg)
117
117
  this.animationQueue = []
118
118
  if (this.currentAnimation) {
@@ -142,7 +142,7 @@ export class ChessboardView {
142
142
  if (this.svg) {
143
143
  Svg.removeElement(this.svg)
144
144
  }
145
- this.svg = Svg.createSvg(this.chessboard.element)
145
+ this.svg = Svg.createSvg(this.chessboard.context)
146
146
  let description = document.createElement("description")
147
147
  description.innerText = "Chessboard"
148
148
  description.id = "svg-description"
@@ -159,8 +159,8 @@ export class ChessboardView {
159
159
  }
160
160
 
161
161
  updateMetrics() {
162
- this.width = this.chessboard.element.clientWidth
163
- this.height = this.chessboard.element.clientHeight
162
+ this.width = this.chessboard.context.clientWidth
163
+ this.height = this.chessboard.context.clientHeight
164
164
  if (this.chessboard.props.style.borderType === BORDER_TYPE.frame) {
165
165
  this.borderSize = this.width / 25
166
166
  } else if (this.chessboard.props.style.borderType === BORDER_TYPE.thin) {
@@ -179,10 +179,10 @@ export class ChessboardView {
179
179
 
180
180
  handleResize() {
181
181
  if (this.chessboard.props.style.aspectRatio) {
182
- this.chessboard.element.style.height = (this.chessboard.element.clientWidth * this.chessboard.props.style.aspectRatio) + "px"
182
+ this.chessboard.context.style.height = (this.chessboard.context.clientWidth * this.chessboard.props.style.aspectRatio) + "px"
183
183
  }
184
- if (this.chessboard.element.clientWidth !== this.width ||
185
- this.chessboard.element.clientHeight !== this.height) {
184
+ if (this.chessboard.context.clientWidth !== this.width ||
185
+ this.chessboard.context.clientHeight !== this.height) {
186
186
  this.updateMetrics()
187
187
  this.redraw()
188
188
  }
@@ -66,7 +66,7 @@ export class ChessboardViewAccessible extends ChessboardView {
66
66
  this.boardAsTableContainer = this.createElement(`<div><h3>${this.th.board_as_table}</h3><div class="table"></div></div>`)
67
67
  this.boardAsTable = this.boardAsTableContainer.querySelector(".table")
68
68
  this.accessibleContainer.appendChild(this.boardAsTableContainer)
69
- this.chessboard.element.appendChild(this.accessibleContainer)
69
+ this.chessboard.context.appendChild(this.accessibleContainer)
70
70
  this.updateFormInputs()
71
71
  }
72
72
 
package/test/TestBoard.js CHANGED
@@ -23,7 +23,7 @@ describe("TestBoard", () => {
23
23
  sprite: {url: "../assets/images/chessboard-sprite.svg"},
24
24
  position: "start"
25
25
  })
26
- assert.equals(chessboard.element.childNodes.length, 1)
26
+ assert.equals(chessboard.context.childNodes.length, 1)
27
27
  chessboard.destroy()
28
28
  assert.equals(chessboard.state, undefined)
29
29
  })