ssb-chess-mithril 2.1.0 → 2.1.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.
Files changed (35) hide show
  1. package/css/chessground-examples/README.md +14 -4
  2. package/css/chessground-examples/assets/3d.css +24 -23
  3. package/css/chessground-examples/assets/chessground.css +73 -15
  4. package/css/chessground-examples/assets/examples.css +1 -1
  5. package/css/chessground-examples/assets/theme.css +37 -26
  6. package/css/chessground-examples/index.html +5 -5
  7. package/css/chessground-examples/package-lock.json +1747 -8086
  8. package/css/chessground-examples/package.json +32 -17
  9. package/css/chessground-examples/pnpm-lock.yaml +874 -0
  10. package/css/chessground-examples/rollup.config.mjs +20 -0
  11. package/css/chessground-examples/src/main.ts +81 -48
  12. package/css/chessground-examples/src/units/anim.ts +63 -42
  13. package/css/chessground-examples/src/units/basics.ts +73 -13
  14. package/css/chessground-examples/src/units/fen.ts +21 -18
  15. package/css/chessground-examples/src/units/in3d.ts +26 -26
  16. package/css/chessground-examples/src/units/perf.ts +29 -15
  17. package/css/chessground-examples/src/units/play.ts +71 -52
  18. package/css/chessground-examples/src/units/svg.ts +230 -102
  19. package/css/chessground-examples/src/units/unit.ts +47 -18
  20. package/css/chessground-examples/src/units/viewOnly.ts +11 -11
  21. package/css/chessground-examples/src/units/zh.ts +25 -23
  22. package/css/chessground-examples/src/util.ts +30 -18
  23. package/css/chessground-examples/tsconfig.json +6 -4
  24. package/css/miniboards.css +1 -0
  25. package/index.js +87 -78
  26. package/package.json +4 -4
  27. package/ui/game/PieceGraveyard.js +1 -1
  28. package/ui/game/chat.js +3 -3
  29. package/ui/game/gameHistory.js +5 -1
  30. package/ui/game/gameView.js +30 -11
  31. package/ui/miniboard/miniboard.js +8 -5
  32. package/ui/pageLayout/navigation.js +11 -7
  33. package/css/chessground-examples/gulpfile.js +0 -52
  34. package/css/chessground-examples/index.standalone.html +0 -17
  35. package/css/chessground-examples/yarn.lock +0 -3529
@@ -0,0 +1,20 @@
1
+ import typescript from "@rollup/plugin-typescript";
2
+ import resolve from "@rollup/plugin-node-resolve";
3
+ import commonjs from "@rollup/plugin-commonjs";
4
+
5
+ export default {
6
+ input: "src/main.ts",
7
+ output: [
8
+ {
9
+ file: "dist/chessground-examples.js",
10
+ format: "iife",
11
+ name: "ChessgroundExamples",
12
+ },
13
+ // {
14
+ // file: 'dist/chessground-examples.min.js',
15
+ // format: 'iife',
16
+ // name: 'ChessgroundExamples',
17
+ // },
18
+ ],
19
+ plugins: [resolve(), typescript(), commonjs()],
20
+ };
@@ -1,15 +1,20 @@
1
- import { h, init } from 'snabbdom';
2
- import { VNode } from 'snabbdom/vnode';
3
- import { Api } from 'chessground/api';
4
- import klass from 'snabbdom/modules/class';
5
- import attributes from 'snabbdom/modules/attributes';
6
- import listeners from 'snabbdom/modules/eventlisteners';
7
- import * as page from 'page'
8
- import { Unit, list } from './units/unit'
1
+ import {
2
+ h,
3
+ init,
4
+ VNode,
5
+ classModule,
6
+ attributesModule,
7
+ eventListenersModule,
8
+ } from "snabbdom";
9
+ import { Api } from "chessground/api";
10
+ import page from "page";
11
+ import { Unit, list } from "./units/unit";
9
12
 
10
13
  export function run(element: Element) {
14
+ const patch = init([classModule, attributesModule, eventListenersModule]);
11
15
 
12
- const patch = init([klass, attributes, listeners]);
16
+ const lastZoom =
17
+ parseFloat(localStorage.getItem("lichess-dev.cge.zoom")!) || 100;
13
18
 
14
19
  let unit: Unit, cg: Api, vnode: VNode;
15
20
 
@@ -19,64 +24,92 @@ export function run(element: Element) {
19
24
 
20
25
  function runUnit(vnode: VNode) {
21
26
  const el = vnode.elm as HTMLElement;
22
- el.className = 'cg-wrap';
27
+ el.className = "cg-wrap";
23
28
  cg = unit.run(el);
24
- window['cg'] = cg; // for messing up with it from the browser console
29
+ window["cg"] = cg; // for messing up with it from the browser console
30
+ if (lastZoom !== 100) setZoom(lastZoom);
25
31
  }
26
32
 
27
33
  function setZoom(zoom: number) {
28
- const el = document.querySelector('.cg-wrap') as HTMLElement;
34
+ const width = (zoom / 100) * 320;
35
+ const el = document.querySelector(".cg-wrap") as HTMLElement;
29
36
  if (el) {
30
- const px = `${zoom / 100 * 320}px`;
31
- el.style.width = px;
32
- el.style.height = px;
33
- document.body.dispatchEvent(new Event('chessground.resize'));
37
+ el.style.width = `${width}px`;
38
+ el.style.height = `${width}px`;
34
39
  }
40
+ const el3d = document.querySelector(".in3d .cg-wrap") as HTMLElement;
41
+ if (el3d) {
42
+ el3d.style.height = `${(width * 464.5) / 512}px`;
43
+ }
44
+ document.body.dispatchEvent(new Event("chessground.resize"));
35
45
  }
36
46
 
37
47
  function render() {
38
- return h('div#chessground-examples', [
39
- h('menu', list.map((ex, id) => {
40
- return h('a', {
41
- class: {
42
- active: unit.name === ex.name
43
- },
44
- on: { click: () => page(`/${id}`) }
45
- }, ex.name);
46
- })),
47
- h('section.blue.merida', [
48
- h('div.cg-wrap', {
48
+ return h("div#chessground-examples", [
49
+ h(
50
+ "menu",
51
+ list.map((ex, id) => {
52
+ return h(
53
+ "a",
54
+ {
55
+ class: {
56
+ active: unit.name === ex.name,
57
+ },
58
+ on: { click: () => page(`/${id}`) },
59
+ },
60
+ ex.name,
61
+ );
62
+ }),
63
+ ),
64
+ h("section.blue.merida", [
65
+ h("div.cg-wrap", {
49
66
  hook: {
50
67
  insert: runUnit,
51
- postpatch: runUnit
52
- }
68
+ postpatch: runUnit,
69
+ },
53
70
  }),
54
- h('p', unit.name)
71
+ h("p", unit.name),
55
72
  ]),
56
- h('control', [
57
- h('button', { on: { click() { cg.toggleOrientation(); }}}, 'Toggle orientation'),
58
- h('label.zoom', [
59
- 'Zoom',
60
- h('input', {
61
- attrs: {
62
- type: 'number',
63
- value: 100
64
- },
73
+ h("control", [
74
+ h(
75
+ "button",
76
+ {
65
77
  on: {
66
- change(e) {
67
- setZoom(parseFloat((e.target as HTMLInputElement).value));
68
- }
69
- }
70
- }, 'Toggle orientation')
71
- ])
72
- ])
78
+ click() {
79
+ cg.toggleOrientation();
80
+ },
81
+ },
82
+ },
83
+ "Toggle orientation",
84
+ ),
85
+ h("label.zoom", [
86
+ "Zoom",
87
+ h(
88
+ "input",
89
+ {
90
+ attrs: {
91
+ type: "number",
92
+ value: lastZoom,
93
+ },
94
+ on: {
95
+ change(e) {
96
+ const zoom = parseFloat((e.target as HTMLInputElement).value);
97
+ localStorage.setItem("lichess-dev.cge.zoom", zoom.toString());
98
+ setZoom(zoom);
99
+ },
100
+ },
101
+ },
102
+ "Toggle orientation",
103
+ ),
104
+ ]),
105
+ ]),
73
106
  ]);
74
107
  }
75
108
 
76
109
  page({ click: false, popstate: false, dispatch: false, hashbang: true });
77
- page('/:id', ctx => {
110
+ page("/:id", (ctx) => {
78
111
  unit = list[parseInt(ctx.params.id) || 0];
79
112
  redraw();
80
113
  });
81
- page(location.hash.slice(2) || '/0');
114
+ page(location.hash.slice(2) || "/0");
82
115
  }
@@ -1,105 +1,126 @@
1
- import { Chessground } from 'chessground';
2
- import { Unit } from './unit';
1
+ import { Chessground } from "@lichess-org/chessground";
2
+ import { Unit } from "./unit";
3
3
 
4
4
  export const conflictingAnim: Unit = {
5
- name: 'Animation: conflict',
5
+ name: "Animation: conflict",
6
6
  run(el) {
7
7
  const cg = Chessground(el, {
8
8
  animation: {
9
- duration: 500
9
+ duration: 500,
10
10
  },
11
- fen: '8/8/5p2/4P3/4K3/8/8/8',
12
- turnColor: 'black',
11
+ fen: "8/8/5p2/4P3/4K3/8/8/8",
12
+ turnColor: "black",
13
13
  movable: {
14
- color: 'white',
15
- free: false
16
- }
14
+ color: "white",
15
+ free: false,
16
+ },
17
17
  });
18
18
  setTimeout(() => {
19
- cg.move('f6', 'e5');
19
+ cg.move("f6", "e5");
20
20
  cg.set({
21
- turnColor: 'white',
21
+ turnColor: "white",
22
22
  movable: {
23
- dests: {e4: ['e5', 'd5', 'f5']}
24
- }
23
+ dests: new Map([["e4", ["e5", "d5", "f5"]]]),
24
+ },
25
25
  });
26
26
  cg.playPremove();
27
27
  }, 2000);
28
28
  return cg;
29
- }
29
+ },
30
30
  };
31
31
 
32
32
  export const withSameRole: Unit = {
33
- name: 'Animation: same role',
33
+ name: "Animation: same role",
34
34
  run(el) {
35
35
  const cg = Chessground(el, {
36
36
  animation: {
37
- duration: 2000
37
+ duration: 2000,
38
38
  },
39
39
  highlight: {
40
- lastMove: false
40
+ lastMove: false,
41
41
  },
42
- fen: '8/8/4p3/5p2/4B3/8/8/8',
43
- turnColor: 'white',
42
+ fen: "8/8/4p3/5p2/4B3/8/8/8",
43
+ turnColor: "white",
44
44
  });
45
45
  setTimeout(() => {
46
- cg.move('e4', 'f5');
46
+ cg.move("e4", "f5");
47
47
  setTimeout(() => {
48
- cg.move('e6', 'f5');
48
+ cg.move("e6", "f5");
49
49
  }, 500);
50
50
  }, 200);
51
51
  return cg;
52
- }
52
+ },
53
53
  };
54
54
 
55
55
  export const notSameRole: Unit = {
56
- name: 'Animation: different role',
56
+ name: "Animation: different role",
57
57
  run(el) {
58
58
  const cg = Chessground(el, {
59
59
  animation: {
60
- duration: 2000
60
+ duration: 2000,
61
61
  },
62
62
  highlight: {
63
- lastMove: false
63
+ lastMove: false,
64
64
  },
65
- fen: '8/8/4n3/5p2/4P3/8/8/8',
66
- turnColor: 'white',
65
+ fen: "8/8/4n3/5p2/4P3/8/8/8",
66
+ turnColor: "white",
67
67
  });
68
68
  setTimeout(() => {
69
- cg.move('e4', 'f5');
69
+ cg.move("e4", "f5");
70
70
  setTimeout(() => {
71
- cg.move('e6', 'f5');
71
+ cg.move("e6", "f5");
72
72
  }, 500);
73
73
  }, 200);
74
74
  return cg;
75
- }
75
+ },
76
76
  };
77
77
 
78
78
  export const whileHolding: Unit = {
79
- name: 'Animation: while holding',
79
+ name: "Animation: while holding",
80
80
  run(el) {
81
81
  const cg = Chessground(el, {
82
- fen: '8/8/5p2/4P3/4K3/8/8/8',
83
- turnColor: 'black',
82
+ fen: "8/8/5p2/4P3/4K3/8/8/8",
83
+ turnColor: "black",
84
84
  animation: {
85
- duration: 5000
85
+ duration: 5000,
86
86
  },
87
87
  movable: {
88
- color: 'white',
88
+ color: "white",
89
89
  free: false,
90
- showDests: false
91
- }
90
+ showDests: false,
91
+ },
92
92
  });
93
93
  setTimeout(() => {
94
- cg.move('f6', 'e5');
94
+ cg.move("f6", "e5");
95
95
  cg.set({
96
- turnColor: 'white',
96
+ turnColor: "white",
97
97
  movable: {
98
- dests: {e4: ['e5', 'd5', 'f5']}
99
- }
98
+ dests: new Map([["e4", ["e5", "d5", "f5"]]]),
99
+ },
100
100
  });
101
101
  cg.playPremove();
102
102
  }, 3000);
103
103
  return cg;
104
- }
104
+ },
105
+ };
106
+
107
+ export const enPassant: Unit = {
108
+ name: "Animation: en passant",
109
+ run(el) {
110
+ const cg = Chessground(el, {
111
+ animation: {
112
+ duration: 2000,
113
+ },
114
+ highlight: {
115
+ lastMove: false,
116
+ },
117
+ fen: "8/8/7p/2K1k1p1/5pP1/5P2/7P/8 b - g3 0 43",
118
+ turnColor: "black",
119
+ orientation: "black",
120
+ });
121
+ setTimeout(() => {
122
+ cg.set({ fen: "8/8/7p/2K1k1p1/8/5Pp1/7P/8 w - - 0 44" });
123
+ }, 500);
124
+ return cg;
125
+ },
105
126
  };
@@ -1,32 +1,92 @@
1
- import { Chessground } from 'chessground';
2
- import { Unit } from './unit';
1
+ import { Chessground } from "@lichess-org/chessground";
2
+ import { Unit } from "./unit";
3
3
 
4
4
  export const defaults: Unit = {
5
- name: 'Default configuration',
5
+ name: "Default configuration",
6
6
  run(el) {
7
7
  return Chessground(el);
8
- }
8
+ },
9
9
  };
10
10
 
11
11
  export const fromFen: Unit = {
12
- name: 'From FEN, from black POV',
12
+ name: "From FEN, from black POV",
13
13
  run(el) {
14
14
  return Chessground(el, {
15
- fen:'2r3k1/pp2Qpbp/4b1p1/3p4/3n1PP1/2N4P/Pq6/R2K1B1R w -',
16
- orientation: 'black'
15
+ fen: "2r3k1/pp2Qpbp/4b1p1/3p4/3n1PP1/2N4P/Pq6/R2K1B1R w -",
16
+ orientation: "black",
17
17
  });
18
- }
18
+ },
19
19
  };
20
20
 
21
21
  export const lastMoveCrazyhouse: Unit = {
22
- name: 'Last move: crazyhouse',
22
+ name: "Last move: crazyhouse",
23
23
  run(el) {
24
24
  const cg = Chessground(el);
25
25
  setTimeout(() => {
26
- cg.set({lastMove:['e2', 'e4']});
27
- setTimeout(() => cg.set({lastMove:['g6']}), 1000);
28
- setTimeout(() => cg.set({lastMove:['e1']}), 2000);
26
+ cg.set({ lastMove: ["e2", "e4"] });
27
+ setTimeout(() => cg.set({ lastMove: ["g6"] }), 1000);
28
+ setTimeout(() => cg.set({ lastMove: ["e1"] }), 2000);
29
29
  });
30
30
  return cg;
31
- }
31
+ },
32
+ };
33
+
34
+ export const checkHighlight: Unit = {
35
+ name: "Highlight king in check",
36
+ run(el) {
37
+ const fen = "r1bqkbnr/1ppppBpp/p1n5/8/4P3/8/PPPP1PPP/RNBQK1NR b KQkq - 0 1";
38
+ const cg = Chessground(el, {
39
+ fen: fen,
40
+ turnColor: "black",
41
+ highlight: {
42
+ check: true,
43
+ },
44
+ });
45
+ cg.set({
46
+ check: true,
47
+ });
48
+ return cg;
49
+ },
50
+ };
51
+
52
+ export const unselectable: Unit = {
53
+ name: "Unselectable, undraggable pieces",
54
+ run(el) {
55
+ return Chessground(el, {
56
+ selectable: {
57
+ enabled: false,
58
+ },
59
+ draggable: {
60
+ enabled: false,
61
+ },
62
+ });
63
+ },
64
+ };
65
+
66
+ export const unselectableDraggable: Unit = {
67
+ name: "Unselectable but draggable pieces",
68
+ run(el) {
69
+ return Chessground(el, {
70
+ selectable: {
71
+ enabled: false,
72
+ },
73
+ draggable: {
74
+ enabled: true,
75
+ },
76
+ });
77
+ },
78
+ };
79
+
80
+ export const selectableUndraggable: Unit = {
81
+ name: "Selectable but undraggable pieces",
82
+ run(el) {
83
+ return Chessground(el, {
84
+ selectable: {
85
+ enabled: true,
86
+ },
87
+ draggable: {
88
+ enabled: false,
89
+ },
90
+ });
91
+ },
32
92
  };
@@ -1,23 +1,26 @@
1
- import { Unit } from './unit';
2
- import { Chessground } from 'chessground';
3
- import { Key } from 'chessground/types.d';
1
+ import { Unit } from "./unit";
2
+ import { Chessground } from "@lichess-org/chessground";
3
+ import { Key } from "@lichess-org/chessground/types.d";
4
4
 
5
5
  export const autoSwitch: Unit = {
6
- name: 'FEN: switch (puzzle bug)',
6
+ name: "FEN: switch (puzzle bug)",
7
7
  run(cont) {
8
- const configs: Array<() => {fen: string; lastMove: Key[]}> = [() => {
9
- return {
10
- orientation: 'black',
11
- fen: 'rnbqkb1r/pp1ppppp/5n2/8/3N1B2/8/PPP1PPPP/RN1QKB1R b KQkq - 0 4',
12
- lastMove: ['f3', 'd4']
13
- };
14
- }, () => {
15
- return {
16
- orientation: 'white',
17
- fen: '2r2rk1/4bp1p/pp2p1p1/4P3/4bP2/PqN1B2Q/1P3RPP/2R3K1 w - - 1 23',
18
- lastMove: ['b4', 'b3']
19
- };
20
- }];
8
+ const configs: Array<() => { fen: string; lastMove: Key[] }> = [
9
+ () => {
10
+ return {
11
+ orientation: "black",
12
+ fen: "rnbqkb1r/pp1ppppp/5n2/8/3N1B2/8/PPP1PPPP/RN1QKB1R b KQkq - 0 4",
13
+ lastMove: ["f3", "d4"],
14
+ };
15
+ },
16
+ () => {
17
+ return {
18
+ orientation: "white",
19
+ fen: "2r2rk1/4bp1p/pp2p1p1/4P3/4bP2/PqN1B2Q/1P3RPP/2R3K1 w - - 1 23",
20
+ lastMove: ["b4", "b3"],
21
+ };
22
+ },
23
+ ];
21
24
  const cg = Chessground(cont, configs[0]());
22
25
  const delay = 2000;
23
26
  let it = 0;
@@ -28,5 +31,5 @@ export const autoSwitch: Unit = {
28
31
  }
29
32
  setTimeout(run, delay);
30
33
  return cg;
31
- }
34
+ },
32
35
  };
@@ -1,10 +1,10 @@
1
- import { Chessground } from 'chessground';
2
- import { Chess } from 'chess.js';
3
- import { Unit } from './unit';
4
- import { toDests, aiPlay } from '../util'
1
+ import { Chessground } from "@lichess-org/chessground";
2
+ import { Chess } from "chess.js";
3
+ import { Unit } from "./unit";
4
+ import { toDests, aiPlay } from "../util";
5
5
 
6
6
  export const defaults: Unit = {
7
- name: '3D theme',
7
+ name: "3D theme",
8
8
  run(cont) {
9
9
  const el = wrapped(cont);
10
10
  const cg = Chessground(el, {
@@ -12,52 +12,52 @@ export const defaults: Unit = {
12
12
  });
13
13
  cg.redrawAll();
14
14
  return cg;
15
- }
16
- }
15
+ },
16
+ };
17
17
 
18
18
  export const vsRandom: Unit = {
19
- name: '3D theme: play vs random AI',
19
+ name: "3D theme: play vs random AI",
20
20
  run(cont) {
21
21
  const el = wrapped(cont);
22
22
  const chess = new Chess();
23
23
  const cg = Chessground(el, {
24
- orientation: 'black',
24
+ orientation: "black",
25
25
  addPieceZIndex: true,
26
26
  movable: {
27
- color: 'white',
27
+ color: "white",
28
28
  free: false,
29
- dests: toDests(chess)
30
- }
29
+ dests: toDests(chess),
30
+ },
31
31
  });
32
32
  cg.redrawAll();
33
33
  cg.set({
34
34
  movable: {
35
35
  events: {
36
- after: aiPlay(cg, chess, 1000, false)
37
- }
38
- }
36
+ after: aiPlay(cg, chess, 1000, false),
37
+ },
38
+ },
39
39
  });
40
40
  return cg;
41
- }
41
+ },
42
42
  };
43
43
 
44
44
  export const fullRandom: Unit = {
45
- name: '3D theme: watch 2 random AIs',
45
+ name: "3D theme: watch 2 random AIs",
46
46
  run(cont) {
47
47
  const el = wrapped(cont);
48
48
  const chess = new Chess();
49
49
  const delay = 300;
50
50
  const cg = Chessground(el, {
51
- orientation: 'black',
51
+ orientation: "black",
52
52
  addPieceZIndex: true,
53
53
  movable: {
54
- free: false
55
- }
54
+ free: false,
55
+ },
56
56
  });
57
57
  cg.redrawAll();
58
58
  function makeMove() {
59
59
  if (!cg.state.dom.elements.board.offsetParent) return;
60
- const moves = chess.moves({verbose:true});
60
+ const moves = chess.moves({ verbose: true });
61
61
  const move = moves[Math.floor(Math.random() * moves.length)];
62
62
  chess.move(move.san);
63
63
  cg.move(move.from, move.to);
@@ -65,13 +65,13 @@ export const fullRandom: Unit = {
65
65
  }
66
66
  setTimeout(makeMove, delay);
67
67
  return cg;
68
- }
69
- }
68
+ },
69
+ };
70
70
 
71
71
  function wrapped(cont: HTMLElement) {
72
- const el = document.createElement('div');
73
- cont.className = 'in3d staunton';
74
- cont.innerHTML = '';
72
+ const el = document.createElement("div");
73
+ cont.className = "in3d staunton";
74
+ cont.innerHTML = "";
75
75
  cont.appendChild(el);
76
76
  return el;
77
77
  }