chess-moments 1.6.0 → 1.6.2

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.
@@ -89,8 +89,38 @@ const momentsToPgn = (moments) => {
89
89
  }
90
90
  }
91
91
 
92
- // Add initial comment if present
93
- if (moment.comment) {
92
+ // Add initial comment and/or shapes if present
93
+ if (moment.shapes && moment.shapes.length > 0) {
94
+ let shapesComment = '';
95
+ const squareHighlights = moment.shapes.filter(
96
+ (s) => !s.dest || s.dest === ']'
97
+ );
98
+ const arrows = moment.shapes.filter((s) => s.dest && s.dest !== ']');
99
+
100
+ if (squareHighlights.length > 0) {
101
+ const coloredSquares = squareHighlights
102
+ .map((s) => `${getBrushCode(s.brush)}${s.orig}`)
103
+ .join(',');
104
+ shapesComment += `[%csl ${coloredSquares}]`;
105
+ }
106
+
107
+ if (arrows.length > 0) {
108
+ const coloredArrows = arrows
109
+ .map((s) => `${getBrushCode(s.brush)}${s.orig}${s.dest}`)
110
+ .join(',');
111
+ if (shapesComment) shapesComment += ' ';
112
+ shapesComment += `[%cal ${coloredArrows}]`;
113
+ }
114
+
115
+ if (shapesComment) {
116
+ const commentText = moment.comment
117
+ ? `${moment.comment} ${shapesComment}`
118
+ : shapesComment;
119
+ pgn += `{${commentText}} `;
120
+ } else if (moment.comment) {
121
+ pgn += `{${moment.comment}} `;
122
+ }
123
+ } else if (moment.comment) {
94
124
  pgn += `{${moment.comment}} `;
95
125
  }
96
126
  continue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chess-moments",
3
- "version": "1.6.0",
3
+ "version": "1.6.2",
4
4
  "description": "PGN parser that transforms PGN files into chess \"moments\"",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -33,5 +33,8 @@
33
33
  "lodash": "^4.17.21",
34
34
  "mocha": "^10.1.0",
35
35
  "prettier": "^2.8.0"
36
+ },
37
+ "overrides": {
38
+ "serialize-javascript": "^7.0.5"
36
39
  }
37
40
  }