@lichess-org/pgn-viewer 2.4.7 → 2.5.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/README.md +23 -0
- package/demo/frame.html +1 -1
- package/demo/index.html +1 -1
- package/demo/lichess-pgn-viewer.css +61 -28
- package/demo/lichess-pgn-viewer.js +697 -379
- package/demo/one.html +6 -6
- package/demo/one.js +1 -1
- package/dist/interfaces.d.ts +2 -1
- package/dist/lichess-pgn-viewer.css +1 -1
- package/dist/lichess-pgn-viewer.min.js +4 -4
- package/dist/pgnViewer.d.ts +1 -0
- package/dist/pgnViewer.js +4 -0
- package/dist/pgnViewer.js.map +1 -1
- package/dist/translation.d.ts +2 -2
- package/dist/translation.js +51 -3
- package/dist/translation.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/view/accessibleBoard.d.ts +3 -0
- package/dist/view/accessibleBoard.js +40 -0
- package/dist/view/accessibleBoard.js.map +1 -0
- package/dist/view/aria.d.ts +10 -0
- package/dist/view/aria.js +54 -0
- package/dist/view/aria.js.map +1 -0
- package/dist/view/glyph.d.ts +9 -0
- package/dist/view/glyph.js +1 -1
- package/dist/view/glyph.js.map +1 -1
- package/dist/view/main.js +9 -0
- package/dist/view/main.js.map +1 -1
- package/dist/view/menu.d.ts +3 -2
- package/dist/view/menu.js +76 -11
- package/dist/view/menu.js.map +1 -1
- package/dist/view/player.js +15 -10
- package/dist/view/player.js.map +1 -1
- package/dist/view/side.js +29 -14
- package/dist/view/side.js.map +1 -1
- package/dist/view/util.d.ts +5 -0
- package/dist/view/util.js +63 -0
- package/dist/view/util.js.map +1 -1
- package/package.json +13 -14
- package/scss/_side.scss +19 -4
- package/scss/_util.scss +10 -0
- package/src/interfaces.ts +2 -2
- package/src/pgnViewer.ts +6 -0
- package/src/translation.ts +53 -4
- package/src/view/accessibleBoard.ts +61 -0
- package/src/view/aria.ts +68 -0
- package/src/view/glyph.ts +1 -1
- package/src/view/main.ts +13 -0
- package/src/view/menu.ts +139 -61
- package/src/view/player.ts +19 -13
- package/src/view/side.ts +40 -16
- package/src/view/util.ts +66 -0
package/src/view/util.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { Hooks } from 'snabbdom';
|
|
2
|
+
import { glyphs } from './glyph';
|
|
3
|
+
import { Translate } from '../interfaces';
|
|
4
|
+
import { Piece, Rank } from 'chessground/types';
|
|
2
5
|
|
|
3
6
|
export function bindMobileMousedown(el: HTMLElement, f: (e: Event) => unknown, redraw?: () => void): void {
|
|
4
7
|
for (const mousedownEvent of ['touchstart', 'mousedown']) {
|
|
@@ -38,3 +41,66 @@ export function onInsert<A extends HTMLElement>(f: (element: A) => void): Hooks
|
|
|
38
41
|
insert: vnode => f(vnode.elm as A),
|
|
39
42
|
};
|
|
40
43
|
}
|
|
44
|
+
|
|
45
|
+
export const clockContent = (seconds: number | undefined): string[] => {
|
|
46
|
+
if (!seconds && seconds !== 0) return ['-'];
|
|
47
|
+
const date = new Date(seconds * 1000),
|
|
48
|
+
sep = ':',
|
|
49
|
+
baseStr = pad2(date.getUTCMinutes()) + sep + pad2(date.getUTCSeconds());
|
|
50
|
+
return seconds >= 3600 ? [Math.floor(seconds / 3600) + sep + baseStr] : [baseStr];
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const pad2 = (num: number): string => (num < 10 ? '0' : '') + num;
|
|
54
|
+
|
|
55
|
+
export const formatSquareForScreenReader = (
|
|
56
|
+
translate: Translate,
|
|
57
|
+
file: string,
|
|
58
|
+
rank: Rank,
|
|
59
|
+
piece?: Piece,
|
|
60
|
+
): string => {
|
|
61
|
+
const square = `${file.toUpperCase()}${rank}`;
|
|
62
|
+
if (!piece) return `${square} ${translate('aria.empty')}`;
|
|
63
|
+
const pieceName = translate(`aria.piece.${piece.role}`);
|
|
64
|
+
return `${square} ${translate(`aria.${piece.color}`)} ${pieceName}`;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export const formatMoveForScreenReader = (san: string, nags?: number[], translate?: Translate): string => {
|
|
68
|
+
let formatted = translate ? transSanToWords(san, translate) : san;
|
|
69
|
+
|
|
70
|
+
if (nags && nags.length > 0) {
|
|
71
|
+
const annotations = nags
|
|
72
|
+
.map(nag => glyphs[nag]?.name)
|
|
73
|
+
.filter(name => name)
|
|
74
|
+
.join(', ');
|
|
75
|
+
|
|
76
|
+
if (annotations) {
|
|
77
|
+
formatted += `, ${annotations}`;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return formatted;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const transSanToWords = (san: string, translate: Translate): string =>
|
|
85
|
+
san
|
|
86
|
+
.split('')
|
|
87
|
+
.map(c => {
|
|
88
|
+
if (c === 'x') return translate('san.takes');
|
|
89
|
+
if (c === '+') return translate('san.check');
|
|
90
|
+
if (c === '#') return translate('san.checkmate');
|
|
91
|
+
if (c === '=') return translate('san.promotesTo');
|
|
92
|
+
if (c === '@') return translate('san.droppedOn');
|
|
93
|
+
const code = c.charCodeAt(0);
|
|
94
|
+
if (code > 48 && code < 58) return c; // 1-8
|
|
95
|
+
if (code > 96 && code < 105) return c.toUpperCase(); // a-h
|
|
96
|
+
if (c === 'K') return translate('aria.piece.king');
|
|
97
|
+
if (c === 'Q') return translate('aria.piece.queen');
|
|
98
|
+
if (c === 'R') return translate('aria.piece.rook');
|
|
99
|
+
if (c === 'B') return translate('aria.piece.bishop');
|
|
100
|
+
if (c === 'N') return translate('aria.piece.knight');
|
|
101
|
+
if (c === 'O') return 'O'; // for castling
|
|
102
|
+
return c;
|
|
103
|
+
})
|
|
104
|
+
.join(' ')
|
|
105
|
+
.replace('O - O - O', translate('san.longCastling'))
|
|
106
|
+
.replace('O - O', translate('san.shortCastling'));
|