kokopu-react 1.11.0 → 2.0.0
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/.eslintrc.yml +84 -0
- package/.nycrc.yml +0 -1
- package/README.md +1 -1
- package/{src/css/chessboard.css → dist/lib/chessboard/Chessboard.css} +2 -2
- package/dist/lib/chessboard/Chessboard.d.ts +171 -0
- package/dist/lib/chessboard/Chessboard.js +365 -0
- package/dist/lib/chessboard/Chessboard.js.map +1 -0
- package/dist/lib/chessboard/ChessboardImpl.d.ts +119 -0
- package/dist/lib/chessboard/ChessboardImpl.js +471 -0
- package/dist/lib/chessboard/ChessboardImpl.js.map +1 -0
- package/dist/lib/chessboard/Draggable.d.ts +62 -0
- package/dist/lib/chessboard/Draggable.js +157 -0
- package/dist/lib/chessboard/Draggable.js.map +1 -0
- package/dist/lib/chessboard/Motion.d.ts +28 -0
- package/dist/lib/chessboard/Motion.js +74 -0
- package/dist/lib/chessboard/Motion.js.map +1 -0
- package/dist/lib/chessboard/colorsets.d.ts +5 -0
- package/dist/lib/{impl → chessboard}/colorsets.js +43 -47
- package/dist/lib/chessboard/colorsets.js.map +1 -0
- package/dist/lib/chessboard/piecesets.d.ts +5 -0
- package/dist/lib/chessboard/piecesets.js +214 -0
- package/dist/lib/chessboard/piecesets.js.map +1 -0
- package/dist/lib/{sprites → chessboard/sprites}/cburnett-bb.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/cburnett-bk.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/cburnett-bn.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/cburnett-bp.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/cburnett-bq.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/cburnett-br.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/cburnett-bx.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/cburnett-wb.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/cburnett-wk.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/cburnett-wn.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/cburnett-wp.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/cburnett-wq.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/cburnett-wr.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/cburnett-wx.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/celtic-bb.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/celtic-bk.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/celtic-bn.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/celtic-bp.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/celtic-bq.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/celtic-br.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/celtic-bx.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/celtic-wb.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/celtic-wk.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/celtic-wn.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/celtic-wp.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/celtic-wq.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/celtic-wr.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/celtic-wx.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/eyes-bb.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/eyes-bk.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/eyes-bn.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/eyes-bp.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/eyes-bq.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/eyes-br.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/eyes-spatial-bx.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/eyes-spatial-wx.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/eyes-wb.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/eyes-wk.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/eyes-wn.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/eyes-wp.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/eyes-wq.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/eyes-wr.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/fantasy-bb.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/fantasy-bk.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/fantasy-bn.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/fantasy-bp.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/fantasy-bq.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/fantasy-br.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/fantasy-bx.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/fantasy-wb.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/fantasy-wk.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/fantasy-wn.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/fantasy-wp.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/fantasy-wq.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/fantasy-wr.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/fantasy-wx.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/skulls-bb.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/skulls-bk.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/skulls-bn.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/skulls-bp.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/skulls-bq.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/skulls-br.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/skulls-bx.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/skulls-wb.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/skulls-wk.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/skulls-wn.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/skulls-wp.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/skulls-wq.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/skulls-wr.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/skulls-wx.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/spatial-bb.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/spatial-bk.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/spatial-bn.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/spatial-bp.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/spatial-bq.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/spatial-br.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/spatial-wb.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/spatial-wk.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/spatial-wn.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/spatial-wp.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/spatial-wq.png +0 -0
- package/dist/lib/{sprites → chessboard/sprites}/spatial-wr.png +0 -0
- package/dist/lib/{css/error_box.css → errorbox/ErrorBox.css} +2 -2
- package/dist/lib/errorbox/ErrorBox.d.ts +28 -0
- package/dist/lib/errorbox/ErrorBox.js +84 -0
- package/dist/lib/errorbox/ErrorBox.js.map +1 -0
- package/dist/lib/exception.d.ts +18 -0
- package/dist/lib/exception.js +40 -0
- package/dist/lib/exception.js.map +1 -0
- package/dist/lib/i18n.d.ts +18 -0
- package/dist/lib/i18n.js +20 -33
- package/dist/lib/i18n.js.map +1 -0
- package/{src/css/symbol.css → dist/lib/icons/AnnotationSymbolShape.css} +2 -2
- package/dist/lib/icons/AnnotationSymbolShape.d.ts +30 -0
- package/dist/lib/{impl/ArrowTip.js → icons/AnnotationSymbolShape.js} +21 -35
- package/dist/lib/icons/AnnotationSymbolShape.js.map +1 -0
- package/dist/lib/icons/ArrowMarkerIcon.d.ts +20 -0
- package/dist/lib/icons/ArrowMarkerIcon.js +53 -0
- package/dist/lib/icons/ArrowMarkerIcon.js.map +1 -0
- package/dist/lib/icons/ArrowTip.d.ts +16 -0
- package/dist/lib/icons/ArrowTip.js +29 -0
- package/dist/lib/icons/ArrowTip.js.map +1 -0
- package/dist/lib/icons/SquareMarkerIcon.d.ts +18 -0
- package/{src/i18n.js → dist/lib/icons/SquareMarkerIcon.js} +24 -23
- package/dist/lib/icons/SquareMarkerIcon.js.map +1 -0
- package/dist/lib/icons/TextMarkerIcon.d.ts +23 -0
- package/dist/lib/icons/TextMarkerIcon.js +45 -0
- package/dist/lib/icons/TextMarkerIcon.js.map +1 -0
- package/{src/css → dist/lib/icons}/arrow.css +2 -2
- package/dist/lib/index.d.ts +10 -0
- package/dist/lib/index.js +31 -105
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/{css/movetext.css → movetext/Movetext.css} +2 -2
- package/dist/lib/movetext/Movetext.d.ts +136 -0
- package/dist/lib/movetext/Movetext.js +167 -0
- package/dist/lib/movetext/Movetext.js.map +1 -0
- package/dist/lib/movetext/MovetextImpl.d.ts +85 -0
- package/dist/lib/movetext/MovetextImpl.js +411 -0
- package/dist/lib/movetext/MovetextImpl.js.map +1 -0
- package/dist/lib/{fonts → movetext/fonts}/chessalpha.woff +0 -0
- package/dist/lib/{fonts → movetext/fonts}/chessalpha.woff2 +0 -0
- package/dist/lib/{css → movetext}/fonts.css +4 -4
- package/dist/lib/movetext/htmlFilter.d.ts +7 -0
- package/dist/lib/movetext/htmlFilter.js +169 -0
- package/dist/lib/movetext/htmlFilter.js.map +1 -0
- package/dist/lib/movetext/moveFormatter.d.ts +20 -0
- package/dist/lib/movetext/moveFormatter.js +93 -0
- package/dist/lib/movetext/moveFormatter.js.map +1 -0
- package/dist/lib/sanitization.d.ts +6 -0
- package/dist/lib/sanitization.js +39 -0
- package/dist/lib/sanitization.js.map +1 -0
- package/dist/lib/types.d.ts +151 -0
- package/dist/lib/types.js +162 -0
- package/dist/lib/types.js.map +1 -0
- package/dist/lib/util.d.ts +2 -0
- package/dist/lib/util.js +36 -0
- package/dist/lib/util.js.map +1 -0
- package/doc_src/demo/{PageChessboardBase.js → PageChessboardBase.tsx} +30 -24
- package/doc_src/demo/{PageChessboardInteraction.js → PageChessboardInteraction.tsx} +95 -66
- package/doc_src/demo/{PageChessboardMove.js → PageChessboardMove.tsx} +66 -54
- package/doc_src/demo/{PageChessboardSmallScreens.js → PageChessboardSmallScreens.tsx} +23 -14
- package/doc_src/demo/{PageMovetextBase.js → PageMovetextBase.tsx} +62 -49
- package/doc_src/demo/{PageMovetextInteraction.js → PageMovetextInteraction.tsx} +58 -43
- package/doc_src/demo/decs.d.ts +31 -0
- package/doc_src/demo/demo.css +2 -2
- package/doc_src/demo/{util.js → util.ts} +3 -3
- package/doc_src/migrate_to_2.md +26 -0
- package/doc_src/theming/LogoRenderer.js +5 -5
- package/doc_src/theming/theming.css +8 -2
- package/package.json +31 -24
- package/scripts/docker-compose.yml +1 -1
- package/scripts/test-graphic.tsconfig.json +7 -0
- package/scripts/test-graphic.webpack.config.js +33 -17
- package/scripts/test-headless.webpack.config.js +6 -10
- package/{dist/lib/css/chessboard.css → src/chessboard/Chessboard.css} +2 -2
- package/src/chessboard/Chessboard.tsx +575 -0
- package/src/chessboard/ChessboardImpl.tsx +632 -0
- package/src/chessboard/Draggable.tsx +252 -0
- package/src/{impl/Motion.js → chessboard/Motion.tsx} +37 -27
- package/src/chessboard/colorsets.ts +134 -0
- package/src/chessboard/piecesets.ts +229 -0
- package/src/{sprites → chessboard/sprites}/cburnett-bb.png +0 -0
- package/src/{sprites → chessboard/sprites}/cburnett-bk.png +0 -0
- package/src/{sprites → chessboard/sprites}/cburnett-bn.png +0 -0
- package/src/{sprites → chessboard/sprites}/cburnett-bp.png +0 -0
- package/src/{sprites → chessboard/sprites}/cburnett-bq.png +0 -0
- package/src/{sprites → chessboard/sprites}/cburnett-br.png +0 -0
- package/src/{sprites → chessboard/sprites}/cburnett-bx.png +0 -0
- package/src/{sprites → chessboard/sprites}/cburnett-wb.png +0 -0
- package/src/{sprites → chessboard/sprites}/cburnett-wk.png +0 -0
- package/src/{sprites → chessboard/sprites}/cburnett-wn.png +0 -0
- package/src/{sprites → chessboard/sprites}/cburnett-wp.png +0 -0
- package/src/{sprites → chessboard/sprites}/cburnett-wq.png +0 -0
- package/src/{sprites → chessboard/sprites}/cburnett-wr.png +0 -0
- package/src/{sprites → chessboard/sprites}/cburnett-wx.png +0 -0
- package/src/{sprites → chessboard/sprites}/celtic-bb.png +0 -0
- package/src/{sprites → chessboard/sprites}/celtic-bk.png +0 -0
- package/src/{sprites → chessboard/sprites}/celtic-bn.png +0 -0
- package/src/{sprites → chessboard/sprites}/celtic-bp.png +0 -0
- package/src/{sprites → chessboard/sprites}/celtic-bq.png +0 -0
- package/src/{sprites → chessboard/sprites}/celtic-br.png +0 -0
- package/src/{sprites → chessboard/sprites}/celtic-bx.png +0 -0
- package/src/{sprites → chessboard/sprites}/celtic-wb.png +0 -0
- package/src/{sprites → chessboard/sprites}/celtic-wk.png +0 -0
- package/src/{sprites → chessboard/sprites}/celtic-wn.png +0 -0
- package/src/{sprites → chessboard/sprites}/celtic-wp.png +0 -0
- package/src/{sprites → chessboard/sprites}/celtic-wq.png +0 -0
- package/src/{sprites → chessboard/sprites}/celtic-wr.png +0 -0
- package/src/{sprites → chessboard/sprites}/celtic-wx.png +0 -0
- package/src/{sprites → chessboard/sprites}/eyes-bb.png +0 -0
- package/src/{sprites → chessboard/sprites}/eyes-bk.png +0 -0
- package/src/{sprites → chessboard/sprites}/eyes-bn.png +0 -0
- package/src/{sprites → chessboard/sprites}/eyes-bp.png +0 -0
- package/src/{sprites → chessboard/sprites}/eyes-bq.png +0 -0
- package/src/{sprites → chessboard/sprites}/eyes-br.png +0 -0
- package/src/{sprites → chessboard/sprites}/eyes-spatial-bx.png +0 -0
- package/src/{sprites → chessboard/sprites}/eyes-spatial-wx.png +0 -0
- package/src/{sprites → chessboard/sprites}/eyes-wb.png +0 -0
- package/src/{sprites → chessboard/sprites}/eyes-wk.png +0 -0
- package/src/{sprites → chessboard/sprites}/eyes-wn.png +0 -0
- package/src/{sprites → chessboard/sprites}/eyes-wp.png +0 -0
- package/src/{sprites → chessboard/sprites}/eyes-wq.png +0 -0
- package/src/{sprites → chessboard/sprites}/eyes-wr.png +0 -0
- package/src/{sprites → chessboard/sprites}/fantasy-bb.png +0 -0
- package/src/{sprites → chessboard/sprites}/fantasy-bk.png +0 -0
- package/src/{sprites → chessboard/sprites}/fantasy-bn.png +0 -0
- package/src/{sprites → chessboard/sprites}/fantasy-bp.png +0 -0
- package/src/{sprites → chessboard/sprites}/fantasy-bq.png +0 -0
- package/src/{sprites → chessboard/sprites}/fantasy-br.png +0 -0
- package/src/{sprites → chessboard/sprites}/fantasy-bx.png +0 -0
- package/src/{sprites → chessboard/sprites}/fantasy-wb.png +0 -0
- package/src/{sprites → chessboard/sprites}/fantasy-wk.png +0 -0
- package/src/{sprites → chessboard/sprites}/fantasy-wn.png +0 -0
- package/src/{sprites → chessboard/sprites}/fantasy-wp.png +0 -0
- package/src/{sprites → chessboard/sprites}/fantasy-wq.png +0 -0
- package/src/{sprites → chessboard/sprites}/fantasy-wr.png +0 -0
- package/src/{sprites → chessboard/sprites}/fantasy-wx.png +0 -0
- package/src/{sprites → chessboard/sprites}/skulls-bb.png +0 -0
- package/src/{sprites → chessboard/sprites}/skulls-bk.png +0 -0
- package/src/{sprites → chessboard/sprites}/skulls-bn.png +0 -0
- package/src/{sprites → chessboard/sprites}/skulls-bp.png +0 -0
- package/src/{sprites → chessboard/sprites}/skulls-bq.png +0 -0
- package/src/{sprites → chessboard/sprites}/skulls-br.png +0 -0
- package/src/{sprites → chessboard/sprites}/skulls-bx.png +0 -0
- package/src/{sprites → chessboard/sprites}/skulls-wb.png +0 -0
- package/src/{sprites → chessboard/sprites}/skulls-wk.png +0 -0
- package/src/{sprites → chessboard/sprites}/skulls-wn.png +0 -0
- package/src/{sprites → chessboard/sprites}/skulls-wp.png +0 -0
- package/src/{sprites → chessboard/sprites}/skulls-wq.png +0 -0
- package/src/{sprites → chessboard/sprites}/skulls-wr.png +0 -0
- package/src/{sprites → chessboard/sprites}/skulls-wx.png +0 -0
- package/src/{sprites → chessboard/sprites}/spatial-bb.png +0 -0
- package/src/{sprites → chessboard/sprites}/spatial-bk.png +0 -0
- package/src/{sprites → chessboard/sprites}/spatial-bn.png +0 -0
- package/src/{sprites → chessboard/sprites}/spatial-bp.png +0 -0
- package/src/{sprites → chessboard/sprites}/spatial-bq.png +0 -0
- package/src/{sprites → chessboard/sprites}/spatial-br.png +0 -0
- package/src/{sprites → chessboard/sprites}/spatial-wb.png +0 -0
- package/src/{sprites → chessboard/sprites}/spatial-wk.png +0 -0
- package/src/{sprites → chessboard/sprites}/spatial-wn.png +0 -0
- package/src/{sprites → chessboard/sprites}/spatial-wp.png +0 -0
- package/src/{sprites → chessboard/sprites}/spatial-wq.png +0 -0
- package/src/{sprites → chessboard/sprites}/spatial-wr.png +0 -0
- package/src/decs.d.ts +26 -0
- package/src/{css/error_box.css → errorbox/ErrorBox.css} +2 -2
- package/src/errorbox/ErrorBox.tsx +129 -0
- package/src/exception.ts +51 -0
- package/src/i18n.ts +43 -0
- package/{dist/lib/css/symbol.css → src/icons/AnnotationSymbolShape.css} +2 -2
- package/src/{impl/TextSymbol.js → icons/AnnotationSymbolShape.tsx} +32 -30
- package/src/{ArrowMarkerIcon.js → icons/ArrowMarkerIcon.tsx} +39 -36
- package/src/{impl/ArrowTip.js → icons/ArrowTip.tsx} +20 -20
- package/src/{SquareMarkerIcon.js → icons/SquareMarkerIcon.tsx} +35 -28
- package/src/{TextMarkerIcon.js → icons/TextMarkerIcon.tsx} +40 -32
- package/{dist/lib/css → src/icons}/arrow.css +2 -2
- package/src/index.ts +38 -0
- package/src/{css/movetext.css → movetext/Movetext.css} +2 -2
- package/src/movetext/Movetext.tsx +278 -0
- package/src/movetext/MovetextImpl.tsx +493 -0
- package/src/{fonts → movetext/fonts}/chessalpha.woff +0 -0
- package/src/{fonts → movetext/fonts}/chessalpha.woff2 +0 -0
- package/src/{css → movetext}/fonts.css +4 -4
- package/src/movetext/htmlFilter.tsx +188 -0
- package/src/{formatmove.js → movetext/moveFormatter.tsx} +39 -26
- package/src/sanitization.ts +51 -0
- package/src/types.ts +311 -0
- package/src/util.ts +39 -0
- package/test/.eslintrc.yml +3 -3
- package/test/{1_markers.js → 01_types.js} +89 -4
- package/test/{2_chessboard_util.js → 02_chessboard_util.js} +16 -7
- package/test/{3_marker_icons_graphic.js → 03_error_box_graphic.js} +20 -14
- package/test/04_marker_icons_graphic.js +49 -0
- package/test/05_chessboard_graphic.js +92 -0
- package/test/06_chessboard_animation.js +71 -0
- package/test/07_chessboard_interaction.js +130 -0
- package/test/08_chessboard_play_moves.js +98 -0
- package/test/{7_movetext_graphic.js → 09_movetext_graphic.js} +32 -16
- package/test/{8_movetext_interaction.js → 10_movetext_interaction.js} +18 -23
- package/test/common/graphic.js +67 -33
- package/test/graphic_references/03_error_box_graphic/base/cut_beginning_of_text.png +0 -0
- package/test/graphic_references/03_error_box_graphic/base/cut_end_of_text.png +0 -0
- package/test/graphic_references/03_error_box_graphic/base/cut_on_line_breaks.png +0 -0
- package/test/graphic_references/03_error_box_graphic/base/error_index_not_integer.png +0 -0
- package/test/graphic_references/03_error_box_graphic/base/full.png +0 -0
- package/test/graphic_references/03_error_box_graphic/base/minimal.png +0 -0
- package/test/graphic_references/03_error_box_graphic/base/missing_error_index.png +0 -0
- package/test/graphic_references/03_error_box_graphic/base/missing_error_text.png +0 -0
- package/test/graphic_references/03_error_box_graphic/base/negative_error_index.png +0 -0
- package/test/graphic_references/03_error_box_graphic/base/single_character_text.png +0 -0
- package/test/graphic_references/03_error_box_graphic/base/too_large_error_index.png +0 -0
- package/test/graphic_references/03_error_box_graphic/localization/default.png +0 -0
- package/test/graphic_references/04_marker_icons_graphic/base/colorized_arrow.png +0 -0
- package/test/{references/01_marker_icons/1.png → graphic_references/04_marker_icons_graphic/base/colorized_square.png} +0 -0
- package/test/graphic_references/04_marker_icons_graphic/base/colorized_symbol.png +0 -0
- package/test/graphic_references/04_marker_icons_graphic/base/colorized_text.png +0 -0
- package/test/graphic_references/04_marker_icons_graphic/base/default_arrow.png +0 -0
- package/test/{references/01_marker_icons/0.png → graphic_references/04_marker_icons_graphic/base/default_square.png} +0 -0
- package/test/graphic_references/04_marker_icons_graphic/base/default_text.png +0 -0
- package/test/graphic_references/04_marker_icons_graphic/base/invalid_arrow_size.png +0 -0
- package/test/graphic_references/04_marker_icons_graphic/base/invalid_square_size.png +0 -0
- package/test/graphic_references/04_marker_icons_graphic/base/invalid_symbol.png +0 -0
- package/test/graphic_references/04_marker_icons_graphic/base/invalid_text_size.png +0 -0
- package/test/graphic_references/04_marker_icons_graphic/base/wrapped_arrow.png +0 -0
- package/test/{references/01_marker_icons/2.png → graphic_references/04_marker_icons_graphic/base/wrapped_square.png} +0 -0
- package/test/graphic_references/04_marker_icons_graphic/base/wrapped_symbol.png +0 -0
- package/test/graphic_references/04_marker_icons_graphic/base/wrapped_text.png +0 -0
- package/test/{references/04_chessboard_annotations/4.png → graphic_references/05_chessboard_graphic/annotations/overlap.png} +0 -0
- package/test/{references/04_chessboard_annotations/5.png → graphic_references/05_chessboard_graphic/annotations/overlap_and_flip.png} +0 -0
- package/test/{references/04_chessboard_annotations/0.png → graphic_references/05_chessboard_graphic/annotations/with_coordinates.png} +0 -0
- package/test/{references/04_chessboard_annotations/1.png → graphic_references/05_chessboard_graphic/annotations/with_coordinates_and_flip.png} +0 -0
- package/test/{references/04_chessboard_annotations/2.png → graphic_references/05_chessboard_graphic/annotations/without_coordinates.png} +0 -0
- package/test/{references/04_chessboard_annotations/3.png → graphic_references/05_chessboard_graphic/annotations/without_coordinates_and_flip.png} +0 -0
- package/test/{references/02_chessboard_simple/0.png → graphic_references/05_chessboard_graphic/base/default.png} +0 -0
- package/test/{references/02_chessboard_simple/1.png → graphic_references/05_chessboard_graphic/base/empty.png} +0 -0
- package/test/{references/02_chessboard_simple/3.png → graphic_references/05_chessboard_graphic/base/from_fen.png} +0 -0
- package/test/{references/02_chessboard_simple/4.png → graphic_references/05_chessboard_graphic/base/from_kokopu_object.png} +0 -0
- package/test/{references/02_chessboard_simple/2.png → graphic_references/05_chessboard_graphic/base/parsing_error.png} +0 -0
- package/test/graphic_references/05_chessboard_graphic/base/wrong_position_type.png +0 -0
- package/test/graphic_references/05_chessboard_graphic/chess_variants/chess960.png +0 -0
- package/test/graphic_references/05_chessboard_graphic/chess_variants/chess960_with_move.png +0 -0
- package/test/graphic_references/05_chessboard_graphic/chess_variants/invalid_variant.png +0 -0
- package/test/graphic_references/05_chessboard_graphic/chess_variants/invalid_variant_with_fen.png +0 -0
- package/test/graphic_references/05_chessboard_graphic/chess_variants/special_code.png +0 -0
- package/test/graphic_references/05_chessboard_graphic/chess_variants/variant_with_std_initial_position.png +0 -0
- package/test/{references/03_chessboard_flipped/2.png → graphic_references/05_chessboard_graphic/chess_variants/variant_without_std_initial_position.png} +0 -0
- package/test/{references/03_chessboard_flipped/0.png → graphic_references/05_chessboard_graphic/flipped/default.png} +0 -0
- package/test/{references/03_chessboard_flipped/1.png → graphic_references/05_chessboard_graphic/flipped/empty.png} +0 -0
- package/test/{references/03_chessboard_flipped/3.png → graphic_references/05_chessboard_graphic/flipped/from_fen.png} +0 -0
- package/test/{references/03_chessboard_flipped/4.png → graphic_references/05_chessboard_graphic/flipped/from_kokopu_object.png} +0 -0
- package/test/graphic_references/05_chessboard_graphic/flipped/parsing_error.png +0 -0
- package/test/{references/05_chessboard_move/4.png → graphic_references/05_chessboard_graphic/move/capture.png} +0 -0
- package/test/{references/05_chessboard_move/5.png → graphic_references/05_chessboard_graphic/move/castling_move.png} +0 -0
- package/test/{references/05_chessboard_move/0.png → graphic_references/05_chessboard_graphic/move/default.png} +0 -0
- package/test/{references/05_chessboard_move/6.png → graphic_references/05_chessboard_graphic/move/en-passant.png} +0 -0
- package/test/{references/05_chessboard_move/1.png → graphic_references/05_chessboard_graphic/move/no_move_arrow.png} +0 -0
- package/test/{references/05_chessboard_move/2.png → graphic_references/05_chessboard_graphic/move/parsing_error.png} +0 -0
- package/test/{references/05_chessboard_move/7.png → graphic_references/05_chessboard_graphic/move/promotion.png} +0 -0
- package/test/{references/05_chessboard_move/3.png → graphic_references/05_chessboard_graphic/move/with_forced_move_arrow_and_flip.png} +0 -0
- package/test/graphic_references/05_chessboard_graphic/move/wrong_move_arrow_color_type.png +0 -0
- package/test/graphic_references/05_chessboard_graphic/move/wrong_move_type.png +0 -0
- package/test/{references/07_chessboard_theme/3.png → graphic_references/05_chessboard_graphic/theme/custom_1.png} +0 -0
- package/test/{references/07_chessboard_theme/4.png → graphic_references/05_chessboard_graphic/theme/custom_2.png} +0 -0
- package/test/{references/07_chessboard_theme/5.png → graphic_references/05_chessboard_graphic/theme/custom_3.png} +0 -0
- package/test/{references/07_chessboard_theme/6.png → graphic_references/05_chessboard_graphic/theme/custom_4.png} +0 -0
- package/test/{references/07_chessboard_theme/7.png → graphic_references/05_chessboard_graphic/theme/custom_5.png} +0 -0
- package/test/{references/07_chessboard_theme/8.png → graphic_references/05_chessboard_graphic/theme/custom_6.png} +0 -0
- package/test/{references/07_chessboard_theme/0.png → graphic_references/05_chessboard_graphic/theme/default.png} +0 -0
- package/test/{references/07_chessboard_theme/1.png → graphic_references/05_chessboard_graphic/theme/large.png} +0 -0
- package/test/{references/07_chessboard_theme/2.png → graphic_references/05_chessboard_graphic/theme/small.png} +0 -0
- package/test/graphic_references/05_chessboard_graphic/theme/wrong_colorset.png +0 -0
- package/test/graphic_references/05_chessboard_graphic/theme/wrong_pieceset.png +0 -0
- package/test/graphic_references/05_chessboard_graphic/theme/wrong_square_size_type.png +0 -0
- package/test/{references/06a_chessboard_animated_move/2.png → graphic_references/06_chessboard_animation/base_1/capture.png} +0 -0
- package/test/{references/06a_chessboard_animated_move/3.png → graphic_references/06_chessboard_animation/base_1/castling_move.png} +0 -0
- package/test/{references/06a_chessboard_animated_move/4.png → graphic_references/06_chessboard_animation/base_1/en-passant.png} +0 -0
- package/test/{references/06a_chessboard_animated_move/0.png → graphic_references/06_chessboard_animation/base_1/move_1.png} +0 -0
- package/test/{references/06a_chessboard_animated_move/1.png → graphic_references/06_chessboard_animation/base_1/move_2.png} +0 -0
- package/test/{references/06a_chessboard_animated_move/5.png → graphic_references/06_chessboard_animation/base_1/promotion.png} +0 -0
- package/test/{references/06b_chessboard_animated_move/2.png → graphic_references/06_chessboard_animation/base_2/capture.png} +0 -0
- package/test/{references/06b_chessboard_animated_move/3.png → graphic_references/06_chessboard_animation/base_2/castling_move.png} +0 -0
- package/test/{references/06b_chessboard_animated_move/4.png → graphic_references/06_chessboard_animation/base_2/en-passant.png} +0 -0
- package/test/{references/06b_chessboard_animated_move/0.png → graphic_references/06_chessboard_animation/base_2/move_1.png} +0 -0
- package/test/{references/06b_chessboard_animated_move/1.png → graphic_references/06_chessboard_animation/base_2/move_2.png} +0 -0
- package/test/{references/06b_chessboard_animated_move/5.png → graphic_references/06_chessboard_animation/base_2/promotion.png} +0 -0
- package/test/{references/06c_chessboard_animated_move/2.png → graphic_references/06_chessboard_animation/base_3/capture.png} +0 -0
- package/test/{references/06c_chessboard_animated_move/3.png → graphic_references/06_chessboard_animation/base_3/castling_move.png} +0 -0
- package/test/{references/06c_chessboard_animated_move/4.png → graphic_references/06_chessboard_animation/base_3/en-passant.png} +0 -0
- package/test/{references/06c_chessboard_animated_move/0.png → graphic_references/06_chessboard_animation/base_3/move_1.png} +0 -0
- package/test/{references/06c_chessboard_animated_move/1.png → graphic_references/06_chessboard_animation/base_3/move_2.png} +0 -0
- package/test/{references/06c_chessboard_animated_move/5.png → graphic_references/06_chessboard_animation/base_3/promotion.png} +0 -0
- package/test/graphic_references/06_chessboard_animation/on_redraw/final_state.png +0 -0
- package/test/graphic_references/06_chessboard_animation/on_redraw/initial_state.png +0 -0
- package/test/{references/10_chessboard_edit_arrows → graphic_references/07_chessboard_interaction/edit_arrows}/base_1.png +0 -0
- package/test/{references/10_chessboard_edit_arrows → graphic_references/07_chessboard_interaction/edit_arrows}/base_2.png +0 -0
- package/test/{references/10_chessboard_edit_arrows/null_vector.png → graphic_references/07_chessboard_interaction/edit_arrows/from_==_to.png} +0 -0
- package/test/{references/10_chessboard_edit_arrows → graphic_references/07_chessboard_interaction/edit_arrows}/out_of_board.png +0 -0
- package/test/{references/10_chessboard_edit_arrows → graphic_references/07_chessboard_interaction/edit_arrows}/over_arrow_marker.png +0 -0
- package/test/{references/10_chessboard_edit_arrows → graphic_references/07_chessboard_interaction/edit_arrows}/over_square_marker.png +0 -0
- package/test/graphic_references/07_chessboard_interaction/error/edit_color_not_set.png +0 -0
- package/test/graphic_references/07_chessboard_interaction/error/wrong_interaction_mode.png +0 -0
- package/test/{references/09_chessboard_move_pieces → graphic_references/07_chessboard_interaction/move_pieces}/after_move.png +0 -0
- package/test/{references/09_chessboard_move_pieces/null_vector.png → graphic_references/07_chessboard_interaction/move_pieces/from_==_to.png} +0 -0
- package/test/{references/09_chessboard_move_pieces/empty_square.png → graphic_references/07_chessboard_interaction/move_pieces/move_empty_square.png} +0 -0
- package/test/{references/09_chessboard_move_pieces → graphic_references/07_chessboard_interaction/move_pieces}/out_of_board.png +0 -0
- package/test/{references/09_chessboard_move_pieces → graphic_references/07_chessboard_interaction/move_pieces}/over_arrow_marker.png +0 -0
- package/test/{references/09_chessboard_move_pieces → graphic_references/07_chessboard_interaction/move_pieces}/over_empty.png +0 -0
- package/test/{references/09_chessboard_move_pieces/over_non_empty_1.png → graphic_references/07_chessboard_interaction/move_pieces/over_non-empty_1.png} +0 -0
- package/test/{references/09_chessboard_move_pieces/over_non_empty_2.png → graphic_references/07_chessboard_interaction/move_pieces/over_non-empty_2.png} +0 -0
- package/test/{references/09_chessboard_move_pieces → graphic_references/07_chessboard_interaction/move_pieces}/over_square_marker.png +0 -0
- package/test/{references/09_chessboard_move_pieces → graphic_references/07_chessboard_interaction/move_pieces}/over_text_marker.png +0 -0
- package/test/{references/11_chessboard_play_moves → graphic_references/08_chessboard_play_moves/base}/castling_move.png +0 -0
- package/test/{references/11_chessboard_play_moves → graphic_references/08_chessboard_play_moves/base}/chess960_ambiguous_king_move.png +0 -0
- package/test/{references/11_chessboard_play_moves → graphic_references/08_chessboard_play_moves/base}/chess960_castling_move_1.png +0 -0
- package/test/{references/11_chessboard_play_moves → graphic_references/08_chessboard_play_moves/base}/chess960_castling_move_2.png +0 -0
- package/test/{references/11_chessboard_play_moves/chess960_non_kxr_castling.png → graphic_references/08_chessboard_play_moves/base/chess960_non-kxr_castling.png} +0 -0
- package/test/{references/11_chessboard_play_moves/null_vector.png → graphic_references/08_chessboard_play_moves/base/from_==_to.png} +0 -0
- package/test/{references/11_chessboard_play_moves → graphic_references/08_chessboard_play_moves/base}/illegal_move.png +0 -0
- package/test/{references/11_chessboard_play_moves → graphic_references/08_chessboard_play_moves/base}/illegal_position.png +0 -0
- package/test/{references/11_chessboard_play_moves → graphic_references/08_chessboard_play_moves/base}/out_of_board.png +0 -0
- package/test/{references/11_chessboard_play_moves → graphic_references/08_chessboard_play_moves/base}/regular_move_1.png +0 -0
- package/test/{references/11_chessboard_play_moves → graphic_references/08_chessboard_play_moves/base}/regular_move_2.png +0 -0
- package/test/{references/10_chessboard_edit_arrows/edit_color_not_set.png → graphic_references/08_chessboard_play_moves/base/wrong_color_moved.png} +0 -0
- package/test/{references/12_chessboard_play_promotions → graphic_references/08_chessboard_play_moves/promotions}/antichess_promotion.png +0 -0
- package/test/{references/12_chessboard_play_promotions → graphic_references/08_chessboard_play_moves/promotions}/cancel_promotion.png +0 -0
- package/test/{references/12_chessboard_play_promotions → graphic_references/08_chessboard_play_moves/promotions}/regular_promotion_1.png +0 -0
- package/test/{references/12_chessboard_play_promotions → graphic_references/08_chessboard_play_moves/promotions}/regular_promotion_2.png +0 -0
- package/test/{references/13_movetext_simple/0.png → graphic_references/09_movetext_graphic/base/game_1.png} +0 -0
- package/test/{references/13_movetext_simple/1.png → graphic_references/09_movetext_graphic/base/game_2.png} +0 -0
- package/test/{references/13_movetext_simple/2.png → graphic_references/09_movetext_graphic/base/game_3.png} +0 -0
- package/test/{references/13_movetext_simple/3.png → graphic_references/09_movetext_graphic/base/game_4.png} +0 -0
- package/test/{references/14_movetext_error/2.png → graphic_references/09_movetext_graphic/error/pgn_parsing_error_1.png} +0 -0
- package/test/{references/14_movetext_error/3.png → graphic_references/09_movetext_graphic/error/pgn_parsing_error_2.png} +0 -0
- package/test/{references/14_movetext_error/0.png → graphic_references/09_movetext_graphic/error/wrong_game_index_1.png} +0 -0
- package/test/{references/14_movetext_error/1.png → graphic_references/09_movetext_graphic/error/wrong_game_index_2.png} +0 -0
- package/test/graphic_references/09_movetext_graphic/error/wrong_game_index_type.png +0 -0
- package/test/graphic_references/09_movetext_graphic/error/wrong_game_type.png +0 -0
- package/test/{references/15_movetext_html/2.png → graphic_references/09_movetext_graphic/html/filtered_tags_and_attributes.png} +0 -0
- package/test/{references/15_movetext_html/1.png → graphic_references/09_movetext_graphic/html/html_in_comments.png} +0 -0
- package/test/{references/15_movetext_html/0.png → graphic_references/09_movetext_graphic/html/html_in_headers.png} +0 -0
- package/test/{references/16_movetext_options/1.png → graphic_references/09_movetext_graphic/options/custom_piece_symbols.png} +0 -0
- package/test/{references/16_movetext_options/2.png → graphic_references/09_movetext_graphic/options/figurine_piece_symbols_and_diagram_options.png} +0 -0
- package/test/{references/16_movetext_options/3.png → graphic_references/09_movetext_graphic/options/hidden_diagrams.png} +0 -0
- package/test/{references/16_movetext_options/0.png → graphic_references/09_movetext_graphic/options/localized_piece_symbols.png} +0 -0
- package/test/graphic_references/09_movetext_graphic/options/wrong_diagram_options_1.png +0 -0
- package/test/graphic_references/09_movetext_graphic/options/wrong_diagram_options_2.png +0 -0
- package/test/graphic_references/10_movetext_interaction/error/wrong_interaction_mode.png +0 -0
- package/test/{references/17_movetext_interaction/0.png → graphic_references/10_movetext_interaction/select_moves/click_on_disabled.png} +0 -0
- package/test/{references/17_movetext_interaction/1.png → graphic_references/10_movetext_interaction/select_moves/click_on_unselected.png} +0 -0
- package/test/{references/17_movetext_interaction/2.png → graphic_references/10_movetext_interaction/select_moves/click_on_with_variations.png} +0 -0
- package/test/graphic_test_app/.eslintrc.yml +5 -0
- package/test/graphic_test_app/03_error_box_graphic/base.tsx +46 -0
- package/{scripts/clean-graphic-output.js → test/graphic_test_app/03_error_box_graphic/localization.tsx} +10 -7
- package/{graphic_test_src/01_marker_icons.js → test/graphic_test_app/04_marker_icons_graphic/base.tsx} +15 -7
- package/{graphic_test_src/04_chessboard_annotations.js → test/graphic_test_app/05_chessboard_graphic/annotations.tsx} +23 -14
- package/{graphic_test_src/02_chessboard_simple.js → test/graphic_test_app/05_chessboard_graphic/base.tsx} +6 -6
- package/test/graphic_test_app/05_chessboard_graphic/chess_variants.tsx +35 -0
- package/{graphic_test_src/03_chessboard_flipped.js → test/graphic_test_app/05_chessboard_graphic/flipped.tsx} +5 -5
- package/{graphic_test_src/05_chessboard_move.js → test/graphic_test_app/05_chessboard_graphic/move.tsx} +9 -8
- package/{graphic_test_src/07_chessboard_theme.js → test/graphic_test_app/05_chessboard_graphic/theme.tsx} +14 -11
- package/{graphic_test_src/06a_chessboard_animated_move.js → test/graphic_test_app/06_chessboard_animation/base_1.tsx} +5 -5
- package/{graphic_test_src/06b_chessboard_animated_move.js → test/graphic_test_app/06_chessboard_animation/base_2.tsx} +5 -5
- package/{graphic_test_src/06c_chessboard_animated_move.js → test/graphic_test_app/06_chessboard_animation/base_3.tsx} +5 -5
- package/test/graphic_test_app/06_chessboard_animation/on_redraw.tsx +49 -0
- package/{graphic_test_src/08_chessboard_click_squares.js → test/graphic_test_app/07_chessboard_interaction/click_squares.tsx} +7 -6
- package/{graphic_test_src/10_chessboard_edit_arrows.js → test/graphic_test_app/07_chessboard_interaction/edit_arrows.tsx} +7 -7
- package/test/graphic_test_app/07_chessboard_interaction/error.tsx +30 -0
- package/{graphic_test_src/09_chessboard_move_pieces.js → test/graphic_test_app/07_chessboard_interaction/move_pieces.tsx} +7 -6
- package/{graphic_test_src/11_chessboard_play_moves.js → test/graphic_test_app/08_chessboard_play_moves/base.tsx} +6 -6
- package/{graphic_test_src/12_chessboard_play_promotions.js → test/graphic_test_app/08_chessboard_play_moves/promotions.tsx} +6 -6
- package/{graphic_test_src/13_movetext_simple.js → test/graphic_test_app/09_movetext_graphic/base.tsx} +8 -8
- package/{graphic_test_src/14_movetext_error.js → test/graphic_test_app/09_movetext_graphic/error.tsx} +10 -9
- package/{graphic_test_src/15_movetext_html.js → test/graphic_test_app/09_movetext_graphic/html.tsx} +7 -7
- package/{graphic_test_src/16_movetext_options.js → test/graphic_test_app/09_movetext_graphic/options.tsx} +9 -6
- package/test/graphic_test_app/10_movetext_interaction/error.tsx +31 -0
- package/{graphic_test_src/17_movetext_interaction.js → test/graphic_test_app/10_movetext_interaction/select_moves.tsx} +7 -7
- package/test/graphic_test_app/common/decs.d.ts +26 -0
- package/{graphic_test_src → test/graphic_test_app}/common/dummy.pgn +0 -0
- package/{graphic_test_src → test/graphic_test_app}/common/games.pgn +1 -1
- package/{graphic_test_src → test/graphic_test_app}/common/heartbeat.txt +0 -0
- package/{graphic_test_src → test/graphic_test_app}/common/smiley.png +0 -0
- package/{graphic_test_src → test/graphic_test_app}/common/test_app.css +11 -2
- package/{graphic_test_src/common/test_app.js → test/graphic_test_app/common/test_app.tsx} +62 -14
- package/tsconfig.json +15 -0
- package/.babelrc +0 -3
- package/dist/lib/ArrowMarkerIcon.js +0 -85
- package/dist/lib/Chessboard.js +0 -1276
- package/dist/lib/ErrorBox.js +0 -125
- package/dist/lib/Movetext.js +0 -805
- package/dist/lib/SquareMarkerIcon.js +0 -69
- package/dist/lib/TextMarkerIcon.js +0 -74
- package/dist/lib/formatmove.js +0 -107
- package/dist/lib/impl/DraggableHandle.js +0 -268
- package/dist/lib/impl/HtmlSanitizer.js +0 -145
- package/dist/lib/impl/Motion.js +0 -109
- package/dist/lib/impl/TextSymbol.js +0 -89
- package/dist/lib/impl/piecesets.js +0 -219
- package/dist/lib/impl/util.js +0 -71
- package/dist/lib/markers.js +0 -144
- package/doc_src/.eslintrc.yml +0 -2
- package/src/Chessboard.js +0 -1034
- package/src/ErrorBox.js +0 -132
- package/src/Movetext.js +0 -671
- package/src/impl/DraggableHandle.js +0 -232
- package/src/impl/HtmlSanitizer.js +0 -126
- package/src/impl/colorsets.js +0 -119
- package/src/impl/piecesets.js +0 -218
- package/src/impl/util.js +0 -68
- package/src/index.js +0 -31
- package/src/markers.js +0 -115
- package/test/4_chessboard_graphic.js +0 -49
- package/test/5_chessboard_interaction.js +0 -135
- package/test/6_chessboard_play_moves.js +0 -107
- package/test/references/01_marker_icons/10.png +0 -0
- package/test/references/01_marker_icons/3.png +0 -0
- package/test/references/01_marker_icons/4.png +0 -0
- package/test/references/01_marker_icons/5.png +0 -0
- package/test/references/01_marker_icons/6.png +0 -0
- package/test/references/01_marker_icons/7.png +0 -0
- package/test/references/01_marker_icons/8.png +0 -0
- package/test/references/01_marker_icons/9.png +0 -0
- package/test/references/02_chessboard_simple/5.png +0 -0
- package/test/references/05_chessboard_move/8.png +0 -0
- package/test/references/11_chessboard_play_moves/wrong_color.png +0 -0
- package/test/references/14_movetext_error/4.png +0 -0
|
@@ -0,0 +1,632 @@
|
|
|
1
|
+
/* -------------------------------------------------------------------------- *
|
|
2
|
+
* *
|
|
3
|
+
* This file is part of Kokopu-React, a JavaScript chess library. *
|
|
4
|
+
* Copyright (C) 2021-2023 Yoann Le Montagner <yo35 -at- melix.net> *
|
|
5
|
+
* *
|
|
6
|
+
* This program is free software: you can redistribute it and/or *
|
|
7
|
+
* modify it under the terms of the GNU Lesser General Public License *
|
|
8
|
+
* as published by the Free Software Foundation, either version 3 of *
|
|
9
|
+
* the License, or (at your option) any later version. *
|
|
10
|
+
* *
|
|
11
|
+
* This program is distributed in the hope that it will be useful, *
|
|
12
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
13
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
14
|
+
* GNU Lesser General Public License for more details. *
|
|
15
|
+
* *
|
|
16
|
+
* You should have received a copy of the GNU Lesser General *
|
|
17
|
+
* Public License along with this program. If not, see *
|
|
18
|
+
* <http://www.gnu.org/licenses/>. *
|
|
19
|
+
* *
|
|
20
|
+
* -------------------------------------------------------------------------- */
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
import * as React from 'react';
|
|
24
|
+
|
|
25
|
+
import { Color, Piece, ColoredPiece, Square, MoveDescriptor, Position, coordinatesToSquare, forEachSquare, oppositeColor, squareColor, squareToCoordinates } from 'kokopu';
|
|
26
|
+
|
|
27
|
+
import { generateRandomId } from '../util';
|
|
28
|
+
import { Colorset, Pieceset, AnnotationColor, SquareMarkerSet, TextMarkerSet, ArrowMarkerSet } from '../types';
|
|
29
|
+
|
|
30
|
+
import { AnnotationSymbolShape } from '../icons/AnnotationSymbolShape';
|
|
31
|
+
import { ArrowTip } from '../icons/ArrowTip';
|
|
32
|
+
import { Draggable } from './Draggable';
|
|
33
|
+
import { Motion } from './Motion';
|
|
34
|
+
|
|
35
|
+
import '../icons/arrow.css';
|
|
36
|
+
import './Chessboard.css';
|
|
37
|
+
|
|
38
|
+
const TURN_FLAG_SPACING_FACTOR = 0.1;
|
|
39
|
+
const RANK_COORDINATE_WIDTH_FACTOR = 1;
|
|
40
|
+
const FILE_COORDINATE_HEIGHT_FACTOR = 1.4;
|
|
41
|
+
const HOVER_MARKER_THICKNESS_FACTOR = 0.1;
|
|
42
|
+
const STROKE_THICKNESS_FACTOR = 0.15;
|
|
43
|
+
const ARROW_TIP_OFFSET_FACTOR = 0.3;
|
|
44
|
+
|
|
45
|
+
const MOTION_DURATION = 150;
|
|
46
|
+
|
|
47
|
+
const RANK_LABELS = '12345678';
|
|
48
|
+
const FILE_LABELS = 'abcdefgh';
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
interface ChessboardImplProps {
|
|
52
|
+
|
|
53
|
+
position: Position;
|
|
54
|
+
move?: MoveDescriptor;
|
|
55
|
+
|
|
56
|
+
squareMarkers?: SquareMarkerSet;
|
|
57
|
+
textMarkers?: TextMarkerSet;
|
|
58
|
+
arrowMarkers?: ArrowMarkerSet;
|
|
59
|
+
|
|
60
|
+
flipped: boolean;
|
|
61
|
+
squareSize: number;
|
|
62
|
+
coordinateVisible: boolean;
|
|
63
|
+
moveArrowVisible: boolean;
|
|
64
|
+
moveArrowColor: AnnotationColor;
|
|
65
|
+
animated: boolean;
|
|
66
|
+
colorset: Colorset;
|
|
67
|
+
pieceset: Pieceset;
|
|
68
|
+
|
|
69
|
+
interactionMode?: 'movePieces' | 'clickSquares' | 'editArrows' | 'playMoves',
|
|
70
|
+
editedArrowColor?: AnnotationColor; // mandatory if `interactionMode === 'editArrows'`
|
|
71
|
+
|
|
72
|
+
onPieceMoved?: (from: Square, to: Square) => void;
|
|
73
|
+
onSquareClicked?: (square: Square) => void;
|
|
74
|
+
onArrowEdited?: (from: Square, to: Square) => void;
|
|
75
|
+
onMovePlayed?: (move: string) => void;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
interface ChessboardImplState {
|
|
80
|
+
inhibitedSquare?: Square;
|
|
81
|
+
draggedSquare?: Square;
|
|
82
|
+
hoveredSquare?: Square;
|
|
83
|
+
dragPosition?: { x: number, y: number }; // mandatory if `dragged` is defined
|
|
84
|
+
cursorOffset?: { x: number, y: number }; // mandatory if `dragged` is defined
|
|
85
|
+
promotionDrawer?: {
|
|
86
|
+
origin: Square,
|
|
87
|
+
buttons: Piece[],
|
|
88
|
+
builder: (promotion: Piece) => string,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Implementation of {@link Chessboard}.
|
|
95
|
+
*
|
|
96
|
+
* This implementation assumes that all the parameter sanitization has been performed beforehand.
|
|
97
|
+
* All the logic related to parameter adaptation in presence of small-screen devices is also performed beforehand.
|
|
98
|
+
*/
|
|
99
|
+
export class ChessboardImpl extends React.Component<ChessboardImplProps, ChessboardImplState> {
|
|
100
|
+
|
|
101
|
+
private arrowTipIdSuffix: string = generateRandomId();
|
|
102
|
+
|
|
103
|
+
constructor(props: ChessboardImplProps) {
|
|
104
|
+
super(props);
|
|
105
|
+
this.state = {};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
render() {
|
|
109
|
+
|
|
110
|
+
let fontSize = 0;
|
|
111
|
+
|
|
112
|
+
// Render the squares.
|
|
113
|
+
const squares: React.ReactNode[] = [];
|
|
114
|
+
forEachSquare(sq => squares.push(this.renderSquare(sq)));
|
|
115
|
+
|
|
116
|
+
// Render coordinates.
|
|
117
|
+
const rankCoordinates: React.ReactNode[] = [];
|
|
118
|
+
const fileCoordinates: React.ReactNode[] = [];
|
|
119
|
+
if (this.props.coordinateVisible) {
|
|
120
|
+
fontSize = computeCoordinateFontSize(this.props.squareSize);
|
|
121
|
+
for (let i = 0; i < 8; ++i) {
|
|
122
|
+
rankCoordinates.push(this.renderRankCoordinate(fontSize, i));
|
|
123
|
+
fileCoordinates.push(this.renderFileCoordinate(fontSize, i));
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Render the whole canvas.
|
|
128
|
+
const xmin = Math.round(-RANK_COORDINATE_WIDTH_FACTOR * fontSize);
|
|
129
|
+
const ymin = 0;
|
|
130
|
+
const xmax = 9 * this.props.squareSize + Math.round(TURN_FLAG_SPACING_FACTOR * this.props.squareSize);
|
|
131
|
+
const ymax = 8 * this.props.squareSize + Math.round(FILE_COORDINATE_HEIGHT_FACTOR * fontSize);
|
|
132
|
+
const viewBox = `${xmin} ${ymin} ${xmax - xmin} ${ymax - ymin}`;
|
|
133
|
+
return (
|
|
134
|
+
<svg className="kokopu-chessboard" viewBox={viewBox} width={xmax - xmin} height={ymax - ymin}>
|
|
135
|
+
<defs>
|
|
136
|
+
{this.renderArrowTip('b')}
|
|
137
|
+
{this.renderArrowTip('g')}
|
|
138
|
+
{this.renderArrowTip('r')}
|
|
139
|
+
{this.renderArrowTip('y')}
|
|
140
|
+
</defs>
|
|
141
|
+
{squares}
|
|
142
|
+
{rankCoordinates}
|
|
143
|
+
{fileCoordinates}
|
|
144
|
+
{this.renderBoardContent()}
|
|
145
|
+
</svg>
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
private renderBoardContent() {
|
|
150
|
+
if (this.props.move && this.props.animated) {
|
|
151
|
+
return (
|
|
152
|
+
<Motion duration={MOTION_DURATION}>
|
|
153
|
+
{motionCursor => (motionCursor === 1 ? this.renderBoardContentStill() : this.renderBoardContentAnimated(motionCursor))}
|
|
154
|
+
</Motion>
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
return this.renderBoardContentStill();
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Render the board content during the animation.
|
|
164
|
+
*/
|
|
165
|
+
private renderBoardContentAnimated(motionCursor: number) {
|
|
166
|
+
const pieces: React.ReactNode[] = [];
|
|
167
|
+
forEachSquare(sq => pieces.push(this.renderPieceAnimated(motionCursor, sq)));
|
|
168
|
+
return (
|
|
169
|
+
<>
|
|
170
|
+
{pieces}
|
|
171
|
+
{this.renderMoveArrow(motionCursor)}
|
|
172
|
+
{this.renderTurnFlag(oppositeColor(this.props.position.turn()))}
|
|
173
|
+
</>
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Render the board content when the animation has been completed (or if there is no animation).
|
|
179
|
+
*/
|
|
180
|
+
private renderBoardContentStill() {
|
|
181
|
+
|
|
182
|
+
const positionStill = this.getPositionStill();
|
|
183
|
+
|
|
184
|
+
// Render the square-related objects.
|
|
185
|
+
const pieces: React.ReactNode[] = [];
|
|
186
|
+
const handles: React.ReactNode[] = [];
|
|
187
|
+
forEachSquare(sq => {
|
|
188
|
+
pieces.push(this.renderPiece(positionStill, sq));
|
|
189
|
+
if (this.props.interactionMode) {
|
|
190
|
+
handles.push(this.renderSquareHandle(positionStill, sq));
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
return (
|
|
194
|
+
<>
|
|
195
|
+
{this.renderSquareMarkers()}
|
|
196
|
+
{this.renderHoveredSquare()}
|
|
197
|
+
{pieces}
|
|
198
|
+
{this.renderTextMarkers()}
|
|
199
|
+
{this.renderArrowMarkers()}
|
|
200
|
+
{this.renderMoveArrow(1)}
|
|
201
|
+
{handles}
|
|
202
|
+
{this.renderPromotionDrawer(positionStill)}
|
|
203
|
+
{this.renderDraggedPiece(positionStill)}
|
|
204
|
+
{this.renderDraggedArrow()}
|
|
205
|
+
{this.renderTurnFlag(positionStill.turn())}
|
|
206
|
+
</>
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
private renderSquare(sq: Square) {
|
|
211
|
+
const { x, y } = this.getSquareCoordinates(sq);
|
|
212
|
+
return <rect key={sq} x={x} y={y} width={this.props.squareSize} height={this.props.squareSize} fill={this.props.colorset[squareColor(sq)]} />;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
private renderHoveredSquare() {
|
|
216
|
+
if (!this.state.hoveredSquare) {
|
|
217
|
+
return undefined;
|
|
218
|
+
}
|
|
219
|
+
const { x, y } = this.getSquareCoordinates(this.state.hoveredSquare);
|
|
220
|
+
const thickness = Math.max(2, Math.round(HOVER_MARKER_THICKNESS_FACTOR * this.props.squareSize));
|
|
221
|
+
const size = this.props.squareSize - thickness;
|
|
222
|
+
const color = this.getColorForAnnotation(this.props.interactionMode === 'editArrows' ? this.props.editedArrowColor! : this.props.moveArrowColor);
|
|
223
|
+
return <rect className="kokopu-hoveredSquare" x={x + thickness / 2} y={y + thickness / 2} width={size} height={size} stroke={color} strokeWidth={thickness} />;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
private renderPiece(positionStill: Position, sq: Square) {
|
|
227
|
+
const cp = positionStill.square(sq);
|
|
228
|
+
if (cp === '-' || this.state.inhibitedSquare === sq) {
|
|
229
|
+
return undefined;
|
|
230
|
+
}
|
|
231
|
+
const { x, y } = this.getSquareCoordinates(sq);
|
|
232
|
+
return <image key={'piece-' + sq} x={x} y={y} width={this.props.squareSize} height={this.props.squareSize} href={this.props.pieceset[cp]} />;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
private renderPieceAnimated(motionCursor: number, sq: Square) {
|
|
236
|
+
const move = this.props.move!;
|
|
237
|
+
let cp = this.props.position.square(sq);
|
|
238
|
+
if (cp === '-' || move.to() === sq || (move.isEnPassant() && move.enPassantSquare() === sq)) {
|
|
239
|
+
return undefined;
|
|
240
|
+
}
|
|
241
|
+
let { x, y } = this.getSquareCoordinates(sq);
|
|
242
|
+
if (sq === move.from()) {
|
|
243
|
+
const { x: xTo, y: yTo } = this.getSquareCoordinates(move.to());
|
|
244
|
+
x = xTo * motionCursor + x * (1 - motionCursor);
|
|
245
|
+
y = yTo * motionCursor + y * (1 - motionCursor);
|
|
246
|
+
if (move.isPromotion() && motionCursor > 0.8) {
|
|
247
|
+
cp = move.coloredPromotion();
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
else if (move.isCastling() && sq === move.rookFrom()) {
|
|
251
|
+
const { x: xTo, y: yTo } = this.getSquareCoordinates(move.rookTo());
|
|
252
|
+
x = xTo * motionCursor + x * (1 - motionCursor);
|
|
253
|
+
y = yTo * motionCursor + y * (1 - motionCursor);
|
|
254
|
+
}
|
|
255
|
+
return <image key={'piece-' + sq} x={x} y={y} width={this.props.squareSize} height={this.props.squareSize} href={this.props.pieceset[cp]} />;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
private renderDraggedPiece(positionStill: Position) {
|
|
259
|
+
if ((this.props.interactionMode !== 'movePieces' && this.props.interactionMode !== 'playMoves') || !this.state.draggedSquare) {
|
|
260
|
+
return undefined;
|
|
261
|
+
}
|
|
262
|
+
const cp = positionStill.square(this.state.draggedSquare) as ColoredPiece; // `draggedSquare` cannot correspond to an empty square
|
|
263
|
+
let { x, y } = this.getSquareCoordinates(this.state.draggedSquare);
|
|
264
|
+
x = Math.min(Math.max(x + this.state.dragPosition!.x, 0), 7 * this.props.squareSize);
|
|
265
|
+
y = Math.min(Math.max(y + this.state.dragPosition!.y, 0), 7 * this.props.squareSize);
|
|
266
|
+
return <image className="kokopu-pieceDraggable kokopu-dragging" x={x} y={y} width={this.props.squareSize} height={this.props.squareSize} href={this.props.pieceset[cp]} />;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
private renderDraggedArrow() {
|
|
270
|
+
if (this.props.interactionMode !== 'editArrows' || !this.state.draggedSquare) {
|
|
271
|
+
return undefined;
|
|
272
|
+
}
|
|
273
|
+
const { x, y } = this.getSquareCoordinates(this.state.draggedSquare);
|
|
274
|
+
const xFrom = x + this.props.squareSize / 2;
|
|
275
|
+
const yFrom = y + this.props.squareSize / 2;
|
|
276
|
+
const xTo = Math.min(Math.max(x + this.state.dragPosition!.x + this.state.cursorOffset!.x, this.props.squareSize / 2), 15 * this.props.squareSize / 2);
|
|
277
|
+
const yTo = Math.min(Math.max(y + this.state.dragPosition!.y + this.state.cursorOffset!.y, this.props.squareSize / 2), 15 * this.props.squareSize / 2);
|
|
278
|
+
if (xFrom === xTo && yFrom === yTo) {
|
|
279
|
+
return undefined;
|
|
280
|
+
}
|
|
281
|
+
const strokeWidth = this.props.squareSize * STROKE_THICKNESS_FACTOR;
|
|
282
|
+
const editArrowColor = this.props.editedArrowColor!;
|
|
283
|
+
return (
|
|
284
|
+
<line
|
|
285
|
+
className="kokopu-annotation kokopu-arrow kokopu-arrowDraggable kokopu-dragging" x1={xFrom} y1={yFrom} x2={xTo} y2={yTo}
|
|
286
|
+
strokeWidth={strokeWidth} stroke={this.getColorForAnnotation(editArrowColor)} markerEnd={`url(#${this.getArrowTipId(editArrowColor)})`}
|
|
287
|
+
/>
|
|
288
|
+
);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
private renderPromotionDrawer(positionStill: Position) {
|
|
292
|
+
if (!this.state.promotionDrawer) {
|
|
293
|
+
return undefined;
|
|
294
|
+
}
|
|
295
|
+
const { x, y } = this.getSquareCoordinates(this.state.promotionDrawer.origin);
|
|
296
|
+
const inverted = positionStill.turn() === (this.props.flipped ? 'w' : 'b'); // false==top-to-bottom true==bottom-to-top
|
|
297
|
+
const y0 = inverted ? y - this.props.squareSize * (this.state.promotionDrawer.buttons.length - 1) : y;
|
|
298
|
+
const buttons = this.state.promotionDrawer.buttons.map((p, i) => {
|
|
299
|
+
const cp = (positionStill.turn() + p) as ColoredPiece;
|
|
300
|
+
return (
|
|
301
|
+
<image
|
|
302
|
+
key={'drawer-piece-' + p} className="kokopu-clickable" x={x} y={y + i * (inverted ? -this.props.squareSize : this.props.squareSize)}
|
|
303
|
+
width={this.props.squareSize} height={this.props.squareSize} href={this.props.pieceset[cp]} onClick={() => this.handleDrawerButtonClicked(p)}
|
|
304
|
+
/>
|
|
305
|
+
);
|
|
306
|
+
});
|
|
307
|
+
return (
|
|
308
|
+
<>
|
|
309
|
+
<rect className="kokopu-handle" x={0} y={0} width={this.props.squareSize * 8} height={this.props.squareSize * 8}
|
|
310
|
+
onClick={() => this.handleDrawerCancelButtonClicked()} />
|
|
311
|
+
<rect x={x} y={y0} width={this.props.squareSize} height={this.props.squareSize * this.state.promotionDrawer.buttons.length}
|
|
312
|
+
fill={this.props.colorset.b} />
|
|
313
|
+
<rect x={x} y={y0} width={this.props.squareSize} height={this.props.squareSize * this.state.promotionDrawer.buttons.length}
|
|
314
|
+
className="kokopu-drawerMask" fill={this.props.colorset.w} />
|
|
315
|
+
{buttons}
|
|
316
|
+
</>
|
|
317
|
+
);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
private renderSquareHandle(positionStill: Position, sq: Square) {
|
|
321
|
+
const { x, y } = this.getSquareCoordinates(sq);
|
|
322
|
+
const dragEnabledForMovePieces = this.props.interactionMode === 'movePieces' && positionStill.square(sq) !== '-';
|
|
323
|
+
const dragEnabledForEditArrows = this.props.interactionMode === 'editArrows';
|
|
324
|
+
const dragEnabledForPlayMoves = this.props.interactionMode === 'playMoves' && !this.state.promotionDrawer && positionStill.isLegal() &&
|
|
325
|
+
positionStill.square(sq).startsWith(positionStill.turn());
|
|
326
|
+
if (dragEnabledForMovePieces || dragEnabledForEditArrows || dragEnabledForPlayMoves) {
|
|
327
|
+
return (
|
|
328
|
+
<Draggable
|
|
329
|
+
key={'handle-' + sq} x={x} y={y} width={this.props.squareSize} height={this.props.squareSize} isArrowHandle={dragEnabledForEditArrows}
|
|
330
|
+
onDragStart={(x0, y0) => this.handleDragStart(sq, x0, y0)}
|
|
331
|
+
onDrag={(dx, dy) => this.handleDrag(sq, dx, dy)}
|
|
332
|
+
onDragStop={(dx, dy) => this.handleDragStop(sq, dx, dy)}
|
|
333
|
+
onDragCanceled={() => this.handleDragCanceled()}
|
|
334
|
+
/>
|
|
335
|
+
);
|
|
336
|
+
}
|
|
337
|
+
else if (this.props.interactionMode === 'clickSquares') {
|
|
338
|
+
return (
|
|
339
|
+
<rect
|
|
340
|
+
key={'handle-' + sq} className="kokopu-handle kokopu-clickable" x={x} y={y} width={this.props.squareSize} height={this.props.squareSize}
|
|
341
|
+
onClick={() => this.handleSquareClicked(sq)}
|
|
342
|
+
/>
|
|
343
|
+
);
|
|
344
|
+
}
|
|
345
|
+
else {
|
|
346
|
+
return undefined;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
private renderSquareMarkers() {
|
|
351
|
+
if (!this.props.squareMarkers) {
|
|
352
|
+
return undefined;
|
|
353
|
+
}
|
|
354
|
+
return Object.entries(this.props.squareMarkers).map(([ sq, color ]) => {
|
|
355
|
+
const { x, y } = this.getSquareCoordinates(sq as Square);
|
|
356
|
+
return (
|
|
357
|
+
<rect key={'sqm-' + sq} className="kokopu-annotation" x={x} y={y} width={this.props.squareSize} height={this.props.squareSize}
|
|
358
|
+
fill={this.getColorForAnnotation(color)}
|
|
359
|
+
/>
|
|
360
|
+
);
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
private renderTextMarkers() {
|
|
365
|
+
if (!this.props.textMarkers) {
|
|
366
|
+
return undefined;
|
|
367
|
+
}
|
|
368
|
+
return Object.entries(this.props.textMarkers).map(([ sq, marker ]) => {
|
|
369
|
+
let { x, y } = this.getSquareCoordinates(sq as Square);
|
|
370
|
+
x += this.props.squareSize / 2;
|
|
371
|
+
y += this.props.squareSize / 2;
|
|
372
|
+
return (
|
|
373
|
+
<g key={'txtm-' + sq} className="kokopu-annotation">
|
|
374
|
+
<AnnotationSymbolShape x={x} y={y} size={this.props.squareSize} symbol={marker.symbol} color={this.getColorForAnnotation(marker.color)} />
|
|
375
|
+
</g>
|
|
376
|
+
);
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
private renderArrowMarkers() {
|
|
381
|
+
if (!this.props.arrowMarkers) {
|
|
382
|
+
return undefined;
|
|
383
|
+
}
|
|
384
|
+
const strokeWidth = this.props.squareSize * STROKE_THICKNESS_FACTOR;
|
|
385
|
+
return Object.entries(this.props.arrowMarkers).map(([ vect, color ]) => {
|
|
386
|
+
const from = vect.substring(0, 2) as Square;
|
|
387
|
+
const to = vect.substring(2, 4) as Square;
|
|
388
|
+
if (from === to) {
|
|
389
|
+
return undefined;
|
|
390
|
+
}
|
|
391
|
+
let { x: xFrom, y: yFrom } = this.getSquareCoordinates(from);
|
|
392
|
+
let { x: xTo, y: yTo } = this.getSquareCoordinates(to);
|
|
393
|
+
xFrom += this.props.squareSize / 2;
|
|
394
|
+
yFrom += this.props.squareSize / 2;
|
|
395
|
+
xTo += this.props.squareSize / 2;
|
|
396
|
+
yTo += this.props.squareSize / 2;
|
|
397
|
+
xTo += Math.sign(xFrom - xTo) * ARROW_TIP_OFFSET_FACTOR * this.props.squareSize;
|
|
398
|
+
yTo += Math.sign(yFrom - yTo) * ARROW_TIP_OFFSET_FACTOR * this.props.squareSize;
|
|
399
|
+
return (
|
|
400
|
+
<line
|
|
401
|
+
key={'arm-' + vect} className="kokopu-annotation kokopu-arrow" x1={xFrom} y1={yFrom} x2={xTo} y2={yTo} strokeWidth={strokeWidth}
|
|
402
|
+
stroke={this.getColorForAnnotation(color)} markerEnd={`url(#${this.getArrowTipId(color)})`}
|
|
403
|
+
/>
|
|
404
|
+
);
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
private renderMoveArrow(motionCursor: number) {
|
|
409
|
+
if (!this.props.move || motionCursor < 0.1 || !this.props.moveArrowVisible || this.props.move.from() === this.props.move.to()) {
|
|
410
|
+
return undefined;
|
|
411
|
+
}
|
|
412
|
+
const strokeWidth = this.props.squareSize * STROKE_THICKNESS_FACTOR;
|
|
413
|
+
let { x: xFrom, y: yFrom } = this.getSquareCoordinates(this.props.move.from());
|
|
414
|
+
xFrom += this.props.squareSize / 2;
|
|
415
|
+
yFrom += this.props.squareSize / 2;
|
|
416
|
+
let { x: xTo, y: yTo } = this.getSquareCoordinates(this.props.move.to());
|
|
417
|
+
xTo += this.props.squareSize / 2;
|
|
418
|
+
yTo += this.props.squareSize / 2;
|
|
419
|
+
xTo += Math.sign(xFrom - xTo) * ARROW_TIP_OFFSET_FACTOR * this.props.squareSize;
|
|
420
|
+
yTo += Math.sign(yFrom - yTo) * ARROW_TIP_OFFSET_FACTOR * this.props.squareSize;
|
|
421
|
+
const x = xTo * motionCursor + xFrom * (1 - motionCursor);
|
|
422
|
+
const y = yTo * motionCursor + yFrom * (1 - motionCursor);
|
|
423
|
+
return (
|
|
424
|
+
<line
|
|
425
|
+
className="kokopu-annotation kokopu-arrow" x1={xFrom} y1={yFrom} x2={x} y2={y} strokeWidth={strokeWidth}
|
|
426
|
+
stroke={this.getColorForAnnotation(this.props.moveArrowColor)} markerEnd={`url(#${this.getArrowTipId(this.props.moveArrowColor)})`}
|
|
427
|
+
/>
|
|
428
|
+
);
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
private renderArrowTip(color: AnnotationColor) {
|
|
432
|
+
return <ArrowTip id={this.getArrowTipId(color)} color={this.getColorForAnnotation(color)} />;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
private renderTurnFlag(turn: Color) {
|
|
436
|
+
const x = 8 * this.props.squareSize + Math.round(TURN_FLAG_SPACING_FACTOR * this.props.squareSize);
|
|
437
|
+
const y = turn === (this.props.flipped ? 'b' : 'w') ? 7 * this.props.squareSize : 0;
|
|
438
|
+
return <image key={'turn-' + turn} x={x} y={y} width={this.props.squareSize} height={this.props.squareSize} href={this.getURLForTurnFlag(turn)} />;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
private renderRankCoordinate(fontSize: number, rank: number) {
|
|
442
|
+
const x = Math.round(-RANK_COORDINATE_WIDTH_FACTOR * fontSize) / 2;
|
|
443
|
+
const y = (this.props.flipped ? rank + 0.5 : 7.5 - rank) * this.props.squareSize;
|
|
444
|
+
const label = RANK_LABELS[rank];
|
|
445
|
+
return <text key={'rank-' + label} className="kokopu-coordinate" x={x} y={y} fontSize={fontSize}>{label}</text>;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
private renderFileCoordinate(fontSize: number, file: number) {
|
|
449
|
+
const x = (this.props.flipped ? 7.5 - file : 0.5 + file) * this.props.squareSize;
|
|
450
|
+
const y = 8 * this.props.squareSize + Math.round(FILE_COORDINATE_HEIGHT_FACTOR * fontSize) / 2;
|
|
451
|
+
const label = FILE_LABELS[file];
|
|
452
|
+
return <text key={'file-' + label} className="kokopu-coordinate" x={x} y={y} fontSize={fontSize}>{label}</text>;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
private handleDragStart(sq: Square, x0: number, y0: number) {
|
|
456
|
+
this.setState({
|
|
457
|
+
inhibitedSquare: this.props.interactionMode === 'movePieces' || this.props.interactionMode === 'playMoves' ? sq : undefined,
|
|
458
|
+
draggedSquare: sq,
|
|
459
|
+
hoveredSquare: sq,
|
|
460
|
+
cursorOffset: { x: x0, y: y0 },
|
|
461
|
+
dragPosition: { x: 0, y: 0 },
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
private handleDrag(sq: Square, dx: number, dy: number) {
|
|
466
|
+
const { x, y } = this.getSquareCoordinates(sq);
|
|
467
|
+
const targetSq = this.getSquareAt(x + dx + this.state.cursorOffset!.x, y + dy + this.state.cursorOffset!.y);
|
|
468
|
+
this.setState({
|
|
469
|
+
hoveredSquare: targetSq,
|
|
470
|
+
dragPosition: { x: dx, y: dy },
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
private handleDragStop(sq: Square, dx: number, dy: number) {
|
|
475
|
+
const { x, y } = this.getSquareCoordinates( sq);
|
|
476
|
+
const targetSq = this.getSquareAt(x + dx + this.state.cursorOffset!.x, y + dy + this.state.cursorOffset!.y);
|
|
477
|
+
this.setState({
|
|
478
|
+
inhibitedSquare: undefined,
|
|
479
|
+
draggedSquare: undefined,
|
|
480
|
+
hoveredSquare: undefined,
|
|
481
|
+
});
|
|
482
|
+
if (sq === targetSq || !targetSq) {
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
if (this.props.interactionMode === 'movePieces' && this.props.onPieceMoved) {
|
|
486
|
+
this.props.onPieceMoved(sq, targetSq);
|
|
487
|
+
}
|
|
488
|
+
else if (this.props.interactionMode === 'editArrows' && this.props.onArrowEdited) {
|
|
489
|
+
this.props.onArrowEdited(sq, targetSq);
|
|
490
|
+
}
|
|
491
|
+
else if (this.props.interactionMode === 'playMoves') {
|
|
492
|
+
const positionStill = this.getPositionStill();
|
|
493
|
+
const info = positionStill.isMoveLegal(sq, targetSq);
|
|
494
|
+
if (!info) {
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
switch (info.status) {
|
|
498
|
+
|
|
499
|
+
// Regular move.
|
|
500
|
+
case 'regular':
|
|
501
|
+
if (this.props.onMovePlayed) {
|
|
502
|
+
this.props.onMovePlayed(positionStill.notation(info()));
|
|
503
|
+
}
|
|
504
|
+
break;
|
|
505
|
+
|
|
506
|
+
// Promotion move.
|
|
507
|
+
case 'promotion':
|
|
508
|
+
this.setState({
|
|
509
|
+
inhibitedSquare: sq, // The moving pawn must not be visible while the promotion drawer is opened.
|
|
510
|
+
promotionDrawer: {
|
|
511
|
+
origin: targetSq,
|
|
512
|
+
buttons: positionStill.variant() === 'antichess' ? [ 'q', 'r', 'b', 'n', 'k' ] : [ 'q', 'r', 'b', 'n' ],
|
|
513
|
+
builder: piece => positionStill.notation(info(piece)),
|
|
514
|
+
},
|
|
515
|
+
});
|
|
516
|
+
break;
|
|
517
|
+
|
|
518
|
+
// Other cases are not supposed to happen.
|
|
519
|
+
// istanbul ignore next
|
|
520
|
+
default:
|
|
521
|
+
break;
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
private handleDragCanceled() {
|
|
527
|
+
this.setState({
|
|
528
|
+
inhibitedSquare: undefined,
|
|
529
|
+
draggedSquare: undefined,
|
|
530
|
+
hoveredSquare: undefined,
|
|
531
|
+
});
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
private handleDrawerCancelButtonClicked() {
|
|
535
|
+
this.setState({
|
|
536
|
+
inhibitedSquare: undefined,
|
|
537
|
+
promotionDrawer: undefined,
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
private handleDrawerButtonClicked(piece: Piece) {
|
|
542
|
+
const builder = this.state.promotionDrawer!.builder;
|
|
543
|
+
this.setState({
|
|
544
|
+
inhibitedSquare: undefined,
|
|
545
|
+
promotionDrawer: undefined,
|
|
546
|
+
});
|
|
547
|
+
if (this.props.onMovePlayed) {
|
|
548
|
+
this.props.onMovePlayed(builder(piece));
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
private handleSquareClicked(sq: Square) {
|
|
553
|
+
if (this.props.onSquareClicked) {
|
|
554
|
+
this.props.onSquareClicked(sq);
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
/**
|
|
559
|
+
* Return the position obtained after playing the move passed among the component props, if any.
|
|
560
|
+
*/
|
|
561
|
+
private getPositionStill() {
|
|
562
|
+
if (!this.props.move) {
|
|
563
|
+
return this.props.position;
|
|
564
|
+
}
|
|
565
|
+
const result = new Position(this.props.position);
|
|
566
|
+
result.play(this.props.move);
|
|
567
|
+
return result;
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
/**
|
|
571
|
+
* Return the (x,y) coordinates of the given square in the SVG canvas.
|
|
572
|
+
*/
|
|
573
|
+
private getSquareCoordinates(sq: Square) {
|
|
574
|
+
const { file, rank } = squareToCoordinates(sq);
|
|
575
|
+
const x = this.props.flipped ? (7 - file) * this.props.squareSize : file * this.props.squareSize;
|
|
576
|
+
const y = this.props.flipped ? rank * this.props.squareSize : (7 - rank) * this.props.squareSize;
|
|
577
|
+
return { x: x, y: y };
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
/**
|
|
581
|
+
* Return the square at the given location.
|
|
582
|
+
*/
|
|
583
|
+
private getSquareAt(x: number, y: number) {
|
|
584
|
+
const file = this.props.flipped ? 7 - Math.floor(x / this.props.squareSize) : Math.floor(x / this.props.squareSize);
|
|
585
|
+
const rank = this.props.flipped ? Math.floor(y / this.props.squareSize) : 7 - Math.floor(y / this.props.squareSize);
|
|
586
|
+
return file >= 0 && file < 8 && rank >= 0 && rank < 8 ? coordinatesToSquare(file, rank) : undefined;
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
/**
|
|
590
|
+
* Return the DOM ID of an arrow tip with the given color.
|
|
591
|
+
*/
|
|
592
|
+
private getArrowTipId(color: AnnotationColor) {
|
|
593
|
+
return `kokopu-arrowTip-${color}-${this.arrowTipIdSuffix}`;
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
/**
|
|
597
|
+
* Return the [CSS color](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value) to use for the given symbolic annotation color.
|
|
598
|
+
*/
|
|
599
|
+
private getColorForAnnotation(color: AnnotationColor) {
|
|
600
|
+
return this.props.colorset[('c' + color) as `c${AnnotationColor}`];
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
/**
|
|
604
|
+
* Return the URL to the image to use for the turn flag of the given color.
|
|
605
|
+
*/
|
|
606
|
+
private getURLForTurnFlag(color: Color) {
|
|
607
|
+
return this.props.pieceset[(color + 'x') as `${Color}x`];
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
|
|
612
|
+
/**
|
|
613
|
+
* Return the size of the chessboard, assuming it is built with the given attributes.
|
|
614
|
+
*/
|
|
615
|
+
export function chessboardSize(squareSize: number, coordinateVisible: boolean) {
|
|
616
|
+
let width = 9 * squareSize + Math.round(TURN_FLAG_SPACING_FACTOR * squareSize);
|
|
617
|
+
let height = 8 * squareSize;
|
|
618
|
+
if (coordinateVisible) {
|
|
619
|
+
const fontSize = computeCoordinateFontSize(squareSize);
|
|
620
|
+
width += Math.round(RANK_COORDINATE_WIDTH_FACTOR * fontSize);
|
|
621
|
+
height += Math.round(FILE_COORDINATE_HEIGHT_FACTOR * fontSize);
|
|
622
|
+
}
|
|
623
|
+
return { width: width, height: height };
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
|
|
627
|
+
/**
|
|
628
|
+
* Return the font size to use for coordinates assuming the given square size.
|
|
629
|
+
*/
|
|
630
|
+
function computeCoordinateFontSize(squareSize: number) {
|
|
631
|
+
return squareSize <= 32 ? 8 : 8 + (squareSize - 32) * 0.2;
|
|
632
|
+
}
|