@@ -145,12 +145,15 @@ <h1 class="clean-pill">{{Themes}}</h1>
145145}
146146
147147/* My Board object */
148- function ChessBoard ( _fenCode , _attrBorder , _colorMode , _attrStyle , _attrClass ) {
148+ function ChessBoard ( _fenCode , _attrBorder , _colorMode , _attrStyle , _attrClass , _flip ) {
149149 this . fenCode = _fenCode ;
150150 this . attrBorder = _attrBorder . split ( ' ' ) ;
151151 this . colorMode = _colorMode ;
152152 this . attrStyle = _attrStyle ;
153153 this . attrClass = _attrClass ;
154+ // When the board is shown from Black's side (180° rotation), the coordinate
155+ // labels must be mirrored: bottom-left becomes h1's mirror, not a1.
156+ this . flip = ! ! _flip ;
154157
155158 this . rowCount = 0 ;
156159 this . colCount = 0 ;
@@ -321,6 +324,13 @@ <h1 class="clean-pill">{{Themes}}</h1>
321324 var generatedHTML = '' ;
322325 this . attrClass = VALUE_CLASS_COLOR_TABLE + ( this . attrClass == '' ? '' : ' ' + this . attrClass ) ;
323326
327+ var colsLabels = MERIDA_COORD_COLS . substr ( this . coordOriginCol , this . colCount ) ;
328+ var rowsLabels = MERIDA_COORD_ROWS . substr ( ( 8 - this . coordOriginRow - this . rowCount ) * 6 , this . rowCount * 6 ) ;
329+ if ( this . flip ) {
330+ colsLabels = colsLabels . split ( '' ) . reverse ( ) . join ( '' ) ;
331+ rowsLabels = rowsLabels . split ( '<br/>' ) . filter ( function ( s ) { return s !== '' ; } ) . reverse ( ) . join ( '<br/>' ) + '<br/>' ;
332+ }
333+
324334 /* ----- Chess table ---------------------------------------------------------------------------------------------------- */
325335 generatedHTML +=
326336 '<table class="' + this . attrClass + '"' + ( this . attrStyle != '' ? ' style="' + this . attrStyle + '"' : '' ) + '>' ;
@@ -332,7 +342,7 @@ <h1 class="clean-pill">{{Themes}}</h1>
332342 generatedHTML +=
333343 ( this . isCoordShownLeft || this . isCoordPadded ? '<td> </td>' : '' ) +
334344 '<td class="cols">' +
335- MERIDA_COORD_COLS . substr ( this . coordOriginCol , this . colCount ) +
345+ colsLabels +
336346 '</td>' +
337347 ( this . isCoordShownRight || this . isCoordPadded ? '<td> </td>' : '' ) +
338348 '' ;
@@ -354,7 +364,7 @@ <h1 class="clean-pill">{{Themes}}</h1>
354364
355365 if ( this . isCoordShownLeft ) {
356366 generatedHTML += '<td class="rows">' ;
357- generatedHTML += MERIDA_COORD_ROWS . substr ( ( 8 - this . coordOriginRow - this . rowCount ) * 6 , this . rowCount * 6 ) ;
367+ generatedHTML += rowsLabels ;
358368 generatedHTML += '</td>' ;
359369 } else if ( this . isCoordPadded ) {
360370 generatedHTML += '<td class="rows">' ;
@@ -433,7 +443,7 @@ <h1 class="clean-pill">{{Themes}}</h1>
433443
434444 if ( this . isCoordShownRight ) {
435445 generatedHTML += '<td class="rows">' ;
436- generatedHTML += MERIDA_COORD_ROWS . substr ( ( 8 - this . coordOriginRow - this . rowCount ) * 6 , this . rowCount * 6 ) ;
446+ generatedHTML += rowsLabels ;
437447 generatedHTML += '</td>' ;
438448 } else if ( this . isCoordPadded ) {
439449 generatedHTML += '<td class="rows">' ;
@@ -450,7 +460,7 @@ <h1 class="clean-pill">{{Themes}}</h1>
450460 generatedHTML +=
451461 ( this . isCoordShownLeft || this . isCoordPadded ? '<td> </td>' : '' ) +
452462 '<td class="cols">' +
453- MERIDA_COORD_COLS . substr ( this . coordOriginCol , this . colCount ) +
463+ colsLabels +
454464 '</td>' +
455465 ( this . isCoordShownRight || this . isCoordPadded ? '<td> </td>' : '' ) +
456466 '' ;
@@ -668,7 +678,8 @@ <h1 class="clean-pill">{{Themes}}</h1>
668678 boardFenCode = chessElt [ idx ] . fenCode ;
669679 }
670680
671- var board = new ChessBoard ( boardFenCode , attrBorder , attrMode , attrStyle , attrClass ) ;
681+ var attrFlip = chessElt [ idx ] . getAttribute ( 'data-flip' ) === '1' ;
682+ var board = new ChessBoard ( boardFenCode , attrBorder , attrMode , attrStyle , attrClass , attrFlip ) ;
672683 var generatedHTML = board . generateHTML ( ) ;
673684 if ( generatedHTML . length == 0 ) {
674685 /* No board position given. Color mode is kept for upcoming chess tags. */
@@ -728,7 +739,10 @@ <h1 class="clean-pill">{{Themes}}</h1>
728739 // 5) Minimal DOM updates (textContent avoids accidental HTML parsing)
729740 const fig = document . getElementById ( 'fen_fig' ) ;
730741 const toMove = document . getElementById ( 'to_move' ) ;
731- if ( fig ) fig . textContent = oriented ;
742+ if ( fig ) {
743+ fig . textContent = oriented ;
744+ fig . setAttribute ( 'data-flip' , side === 'w' ? '0' : '1' ) ;
745+ }
732746 if ( toMove ) toMove . textContent = side === 'w' ? dict . white : dict . black ;
733747
734748 // 6) coords button label (shared from same dict, avoids a second lang lookup)
@@ -742,9 +756,6 @@ <h1 class="clean-pill">{{Themes}}</h1>
742756 const table = document . querySelector ( 'table.chess, table.bwchess' ) ;
743757 if ( ! table ) return ;
744758
745- // Measure the real board box (more reliable than the table alone)
746- const board = table . querySelector ( 'td.board > div.board' ) || table ;
747-
748759 // Reset any previous fitting
749760 table . style . zoom = '' ;
750761 table . style . transform = '' ;
@@ -764,8 +775,9 @@ <h1 class="clean-pill">{{Themes}}</h1>
764775 const maxW = Math . max ( 50 , vw - margin * 2 ) ;
765776 const maxH = Math . max ( 50 , vh - overhead - margin * 2 ) ;
766777
767- // Measure actual current board size
768- const rect = board . getBoundingClientRect ( ) ;
778+ // Measure the full table (board + coordinate cells) so the right-hand
779+ // coordinates never push the board off-screen when shown.
780+ const rect = table . getBoundingClientRect ( ) ;
769781
770782 // Fit factor (never upscale; only shrink)
771783 let z = Math . min ( maxW / rect . width , maxH / rect . height , 1 ) ;
0 commit comments