cm-chess 3.0.1 → 3.1.1

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-chess",
3
- "version": "3.0.1",
3
+ "version": "3.1.1",
4
4
  "description": "It's like chess.js, but in ES6 and can handle variations (tree-structured move history)",
5
5
  "main": "./src/Chess.js",
6
6
  "type": "module",
@@ -25,8 +25,8 @@
25
25
  "homepage": "https://github.com/shaack/cm-chess#readme",
26
26
  "dependencies": {
27
27
  "chess.mjs": "^1.4.0",
28
- "cm-pgn": "3.1.3",
29
- "node-modules-url": "^1.0.3"
28
+ "cm-pgn": "3.1.4",
29
+ "import-node-modules": "^1.0.6"
30
30
  },
31
31
  "devDependencies": {
32
32
  "teevi": "^2.2.4"
package/src/Chess.js CHANGED
@@ -3,9 +3,9 @@
3
3
  * Repository: https://github.com/shaack/cm-chess
4
4
  * License: MIT, see file 'LICENSE'
5
5
  */
6
- const {Pgn} = await import(nodeModulesUrl + "cm-pgn/src/Pgn.js")
7
- const {TAGS} = await import(nodeModulesUrl + "cm-pgn/src/Header.js")
8
- const {Chess: ChessJs, SQUARES} = await import(nodeModulesUrl + "chess.mjs/src/Chess.js")
6
+ const {Pgn} = await import(`${node_modules}/cm-pgn/src/Pgn.js`)
7
+ const {TAGS} = await import(`${node_modules}/cm-pgn/src/Header.js`)
8
+ const {Chess: ChessJs, SQUARES} = await import(`${node_modules}/chess.mjs/src/Chess.js`)
9
9
 
10
10
  export const PIECES = {
11
11
  p: {name: "pawn", value: 1},
@@ -33,10 +33,10 @@ export const EVENT_TYPE = {
33
33
  initialized: "initialized"
34
34
  }
35
35
 
36
- function publishEvent(observers, eventType, data = {}) {
36
+ function publishEvent(observers, event) {
37
37
  for (const observer of observers) {
38
38
  setTimeout(() => {
39
- observer(eventType, data)
39
+ observer(event)
40
40
  })
41
41
  }
42
42
  }
@@ -182,7 +182,7 @@ export class Chess {
182
182
  } else {
183
183
  throw Error("Invalid fen " + fen)
184
184
  }
185
- publishEvent(this.observers, EVENT_TYPE.initialized, {fen: fen})
185
+ publishEvent(this.observers, {type: EVENT_TYPE.initialized, fen: fen})
186
186
  }
187
187
 
188
188
  /**
@@ -192,7 +192,7 @@ export class Chess {
192
192
  */
193
193
  loadPgn(pgn) {
194
194
  this.pgn = new Pgn(pgn)
195
- publishEvent(this.observers, EVENT_TYPE.initialized, {pgn: pgn})
195
+ publishEvent(this.observers, {type: EVENT_TYPE.initialized, pgn: pgn})
196
196
  }
197
197
 
198
198
  /**
@@ -205,10 +205,12 @@ export class Chess {
205
205
  move(move, previousMove = undefined, sloppy = true) {
206
206
  try {
207
207
  const moveResult = this.pgn.history.addMove(move, previousMove, sloppy)
208
- publishEvent(this.observers, EVENT_TYPE.legalMove, {move: move, previousMove: previousMove})
208
+ publishEvent(this.observers,
209
+ {type: EVENT_TYPE.legalMove, move: move, previousMove: previousMove})
209
210
  return moveResult
210
211
  } catch (e) {
211
- publishEvent(this.observers, EVENT_TYPE.illegalMove, {move: move, previousMove: previousMove})
212
+ publishEvent(this.observers,
213
+ {type: EVENT_TYPE.illegalMove, move: move, previousMove: previousMove})
212
214
  return null
213
215
  }
214
216
  }
@@ -257,7 +259,7 @@ export class Chess {
257
259
  * @returns {string} the PGN of the game.
258
260
  */
259
261
  renderPgn(renderHeader = true, renderComments = true, renderNags = true) {
260
- return this.pgn.render(renderHeader, renderComments, renderNags);
262
+ return this.pgn.render(renderHeader, renderComments, renderNags)
261
263
  }
262
264
 
263
265
  /**
@@ -317,7 +319,7 @@ export class Chess {
317
319
  return element.ply === move.ply
318
320
  })
319
321
  move.variation = move.variation.splice(index)
320
- publishEvent(this.observers, EVENT_TYPE.undoMove, {move: move})
322
+ publishEvent(this.observers, {type: EVENT_TYPE.undoMove, move: move})
321
323
  }
322
324
 
323
325
  plyCount() {
package/test/TestChess.js CHANGED
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * @author Stefan Haack (https://shaack.com)
3
3
  */
4
- const {TAGS} = await import(nodeModulesUrl + "cm-pgn/src/Header.js")
5
- import {Chess, COLOR, FEN} from "../src/Chess.js"
4
+ const {TAGS} = await import(`${node_modules}/cm-pgn/src/Header.js`)
6
5
  import {describe, it, assert} from "../node_modules/teevi/src/teevi.js"
6
+ import {Chess, COLOR, FEN} from "../src/Chess.js"
7
7
 
8
8
  describe("Chess", function () {
9
9
 
@@ -225,8 +225,8 @@ Kc4 7. Qb4+ Kd5 8. Qc5#) 5. Bc5# 1-0`)
225
225
  it("should publish events", function() {
226
226
  return new Promise((resolve, reject) => {
227
227
  const chess = new Chess()
228
- chess.addObserver((event, data) => {
229
- if(event === "legalMove" && data.move === "e4") {
228
+ chess.addObserver((event) => {
229
+ if(event.type === "legalMove" && event.move === "e4") {
230
230
  resolve()
231
231
  } else {
232
232
  reject("error event")
package/test/index.html CHANGED
@@ -4,7 +4,7 @@
4
4
  <title>cm-chess tests</title>
5
5
  </head>
6
6
  <body>
7
- <script type="module" src="../node_modules/node-modules-url/node-modules-url.js"></script>
7
+ <script type="module" src="../node_modules/import-node-modules/index.js"></script>
8
8
  <script type="module">
9
9
  import {teevi} from "../node_modules/teevi/src/teevi.js"
10
10
  import "./TestChess.js"