cm-chessboard 7.6.2 → 7.6.4

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
@@ -380,6 +380,8 @@ const chessboard = new Chessboard(document.getElementById("board"), {
380
380
 
381
381
  ### registerMethod(name, callback)
382
382
 
383
+ > Deprecated 2023-05-18, just add methods directly to the chessboard class instance.
384
+
383
385
  Add methods to the main chessboard from your extension with `this.registerMethod("name", callback)`
384
386
  like `addArrow(type, from, to)` in the
385
387
  [Arrows extension](https://shaack.com/projekte/cm-chessboard/examples/extensions/arrows-extension.html).
@@ -47,7 +47,7 @@ function inputHandler(event) {
47
47
  <script type="module">
48
48
  import {INPUT_EVENT_TYPE, Chessboard} from "../src/Chessboard.js"
49
49
  import {FEN} from "../src/model/Position.js"
50
- import {MARKER_TYPE, Markers} from "../src/extensions/markers/Markers.js"
50
+ import {Markers} from "../src/extensions/markers/Markers.js"
51
51
 
52
52
  window.board = new Chessboard(document.getElementById("board"), {
53
53
  position: FEN.start,
@@ -59,8 +59,7 @@ function inputHandler(event) {
59
59
  window.board.enableMoveInput(inputHandler)
60
60
 
61
61
  function inputHandler(event) {
62
- console.log(event)
63
- window.board.removeMarkers(MARKER_TYPE.frame)
62
+ // console.log(event)
64
63
  switch (event.type) {
65
64
  case INPUT_EVENT_TYPE.moveInputStarted:
66
65
  log(`moveInputStarted: ${event.square}`)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cm-chessboard",
3
- "version": "7.6.2",
3
+ "version": "7.6.4",
4
4
  "description": "A JavaScript chessboard which is lightweight, ES6 module based, responsive, SVG rendered and without dependencies.",
5
5
  "keywords": [
6
6
  "chess",
@@ -29,6 +29,6 @@
29
29
  },
30
30
  "homepage": "https://github.com/shaack/cm-chessboard#readme",
31
31
  "devDependencies": {
32
- "teevi": "^2.2.2"
32
+ "teevi": "^2.2.4"
33
33
  }
34
34
  }
@@ -14,6 +14,8 @@ export const ARROW_TYPE = {
14
14
  }
15
15
 
16
16
  export class Arrows extends Extension {
17
+
18
+ /** @constructor */
17
19
  constructor(chessboard, props = {}) {
18
20
  super(chessboard)
19
21
  this.registerExtensionPoint(EXTENSION_POINT.redrawBoard, () => {
@@ -27,9 +29,9 @@ export class Arrows extends Extension {
27
29
  this.chessboard.view.cacheSpriteToDiv("cm-chessboard-arrows",
28
30
  this.chessboard.props.assetsUrl + "extensions/arrows/" + this.props.sprite)
29
31
  }
30
- this.registerMethod("addArrow", this.addArrow)
31
- this.registerMethod("getArrows", this.getArrows)
32
- this.registerMethod("removeArrows", this.removeArrows)
32
+ chessboard.addArrow = this.addArrow.bind(this)
33
+ chessboard.getArrows = this.getArrows.bind(this)
34
+ chessboard.removeArrows = this.removeArrows.bind(this)
33
35
  this.arrowGroup = Svg.addElement(chessboard.view.markersTopLayer, "g", {class: "arrows"})
34
36
  this.arrows = []
35
37
  }
@@ -21,6 +21,8 @@ export const MARKER_TYPE = {
21
21
  }
22
22
 
23
23
  export class Markers extends Extension {
24
+
25
+ /** @constructor */
24
26
  constructor(chessboard, props = {}) {
25
27
  super(chessboard)
26
28
  this.registerExtensionPoint(EXTENSION_POINT.redrawBoard, () => {
@@ -31,19 +33,18 @@ export class Markers extends Extension {
31
33
  sprite: "markers.svg" // the sprite file of the markers
32
34
  }
33
35
  Object.assign(this.props, props)
34
- this.autoMarker = {}
35
36
  if (chessboard.props.assetsCache) {
36
37
  chessboard.view.cacheSpriteToDiv("cm-chessboard-markers", this.chessboard.props.assetsUrl +
37
38
  "extensions/markers/" + this.props.sprite)
38
39
  }
39
- this.registerMethod("addMarker", this.addMarker)
40
- this.registerMethod("getMarkers", this.getMarkers)
41
- this.registerMethod("removeMarkers", this.removeMarkers)
40
+ chessboard.addMarker = this.addMarker.bind(this)
41
+ chessboard.getMarkers = this.getMarkers.bind(this)
42
+ chessboard.removeMarkers = this.removeMarkers.bind(this)
42
43
  this.markerGroupDown = Svg.addElement(chessboard.view.markersLayer, "g", {class: "markers"})
43
44
  this.markerGroupUp = Svg.addElement(chessboard.view.markersTopLayer, "g", {class: "markers"})
44
45
  this.markers = []
45
46
  if (this.props.autoMarkers) {
46
- Object.assign(this.autoMarker, this.props.autoMarkers)
47
+ Object.assign(this.props.autoMarkers, this.props.autoMarkers)
47
48
  this.registerExtensionPoint(EXTENSION_POINT.moveInput, (event) => {
48
49
  this.drawAutoMarkers(event)
49
50
  })
@@ -51,7 +52,9 @@ export class Markers extends Extension {
51
52
  }
52
53
 
53
54
  drawAutoMarkers(event) {
54
- this.removeMarkers(this.autoMarker)
55
+ if(event.type !== INPUT_EVENT_TYPE.moveInputFinished) {
56
+ this.removeMarkers(this.props.autoMarkers)
57
+ }
55
58
  if (event.type === INPUT_EVENT_TYPE.moveInputStarted &&
56
59
  !event.moveInputCallbackResult) {
57
60
  return
@@ -59,10 +62,10 @@ export class Markers extends Extension {
59
62
  if (event.type === INPUT_EVENT_TYPE.moveInputStarted ||
60
63
  event.type === INPUT_EVENT_TYPE.movingOverSquare) {
61
64
  if (event.squareFrom) {
62
- this.addMarker(this.autoMarker, event.squareFrom)
65
+ this.addMarker(this.props.autoMarkers, event.squareFrom)
63
66
  }
64
67
  if (event.squareTo) {
65
- this.addMarker(this.autoMarker, event.squareTo)
68
+ this.addMarker(this.props.autoMarkers, event.squareTo)
66
69
  }
67
70
  }
68
71
  }
@@ -17,11 +17,12 @@ const DISPLAY_STATE = {
17
17
 
18
18
  export class PromotionDialog extends Extension {
19
19
 
20
+ /** @constructor */
20
21
  constructor(chessboard) {
21
22
  super(chessboard)
22
23
  this.registerExtensionPoint(EXTENSION_POINT.redrawBoard, this.extensionPointRedrawBoard.bind(this))
23
24
  this.registerExtensionPoint(EXTENSION_POINT.animation, this.extensionPointAnimation.bind(this))
24
- this.registerMethod("showPromotionDialog", this.showPromotionDialog)
25
+ chessboard.showPromotionDialog = this.showPromotionDialog.bind(this)
25
26
  this.promotionDialogGroup = Svg.addElement(chessboard.view.interactiveTopLayer, "g", {class: "promotion-dialog-group"})
26
27
  this.state = {
27
28
  displayState: DISPLAY_STATE.hidden,
@@ -9,6 +9,7 @@ import {ANIMATION_EVENT_TYPE} from "../../view/PositionAnimationsQueue.js"
9
9
 
10
10
  export class RenderVideo extends Extension {
11
11
 
12
+ /** @constructor */
12
13
  constructor(chessboard, props) {
13
14
  super(chessboard)
14
15
  this.props = {
@@ -38,7 +39,7 @@ export class RenderVideo extends Extension {
38
39
  }
39
40
  }
40
41
  })
41
- this.registerMethod("recorderInit", () => {
42
+ chessboard.recorderInit = () => {
42
43
  return new Promise((resolve) => {
43
44
  let all = document.querySelectorAll("svg *")
44
45
  for (let i = 0; i < all.length; i++) {
@@ -72,8 +73,8 @@ export class RenderVideo extends Extension {
72
73
  resolve()
73
74
  }, 100)
74
75
  })
75
- })
76
- this.registerMethod("recorderStart", () => {
76
+ }
77
+ chessboard.recorderStart = () => {
77
78
  return new Promise((resolve) => {
78
79
  if (this.recorder && this.recorder.state === "recording") {
79
80
  console.error("recorder is running")
@@ -84,11 +85,11 @@ export class RenderVideo extends Extension {
84
85
  console.log("recorder", this.recorder.state)
85
86
  resolve()
86
87
  })
87
- })
88
+ }
88
89
  /**
89
90
  * returns the url of the recorded media
90
91
  */
91
- this.registerMethod("recorderStop", () => {
92
+ chessboard.recorderStop = () => {
92
93
  return new Promise(async (resolve, reject) => {
93
94
  if (!this.recorder || this.recorder.state !== "recording") {
94
95
  reject("recorder is not recording")
@@ -100,8 +101,8 @@ export class RenderVideo extends Extension {
100
101
  resolve(URL.createObjectURL(new Blob(this.recordedData, {type: this.props.mediaType})))
101
102
  }, 200)
102
103
  })
103
- })
104
- this.registerMethod("recorderPause", (ms) => {
104
+ }
105
+ chessboard.recorderPause = (ms) => {
105
106
  return new Promise(async (resolve) => {
106
107
  await this.cloneImageAndRender()
107
108
  const interval = setInterval(async () => {
@@ -113,7 +114,7 @@ export class RenderVideo extends Extension {
113
114
  resolve()
114
115
  }, ms)
115
116
  })
116
- })
117
+ }
117
118
  }
118
119
 
119
120
  async cloneImageAndRender() {
@@ -27,7 +27,9 @@ export class Extension {
27
27
  this.chessboard.state.extensionPoints[name].push(callback)
28
28
  }
29
29
 
30
+ /** @deprecated 2023-05-18 */
30
31
  registerMethod(name, callback) {
32
+ console.warn("registerMethod is deprecated, just add methods directly to the chessboard instance")
31
33
  if (!this.chessboard[name]) {
32
34
  this.chessboard[name] = (...args) => {
33
35
  return callback.apply(this, args)