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
package/dist/lib/Chessboard.js
DELETED
|
@@ -1,1276 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports["default"] = void 0;
|
|
7
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
8
|
-
var _react = _interopRequireDefault(require("react"));
|
|
9
|
-
var _kokopu = require("kokopu");
|
|
10
|
-
var _colorsets2 = _interopRequireDefault(require("./impl/colorsets"));
|
|
11
|
-
var _piecesets2 = _interopRequireDefault(require("./impl/piecesets"));
|
|
12
|
-
var _ArrowTip = _interopRequireDefault(require("./impl/ArrowTip"));
|
|
13
|
-
var _DraggableHandle = _interopRequireDefault(require("./impl/DraggableHandle"));
|
|
14
|
-
var _Motion = _interopRequireDefault(require("./impl/Motion"));
|
|
15
|
-
var _TextSymbol = _interopRequireDefault(require("./impl/TextSymbol"));
|
|
16
|
-
var _ErrorBox = _interopRequireDefault(require("./ErrorBox"));
|
|
17
|
-
var _i18n = _interopRequireDefault(require("./i18n"));
|
|
18
|
-
var _markers = require("./markers");
|
|
19
|
-
var _util = require("./impl/util");
|
|
20
|
-
require("./css/chessboard.css");
|
|
21
|
-
require("./css/arrow.css");
|
|
22
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
23
|
-
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
24
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
25
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
26
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
27
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
28
|
-
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0) { ; } } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
29
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
30
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
31
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
32
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
33
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
34
|
-
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
35
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
36
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
37
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
38
|
-
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
39
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
40
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
41
|
-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
42
|
-
var TURN_FLAG_SPACING_FACTOR = 0.1;
|
|
43
|
-
var RANK_COORDINATE_WIDTH_FACTOR = 1;
|
|
44
|
-
var FILE_COORDINATE_HEIGHT_FACTOR = 1.4;
|
|
45
|
-
var HOVER_MARKER_THICKNESS_FACTOR = 0.1;
|
|
46
|
-
var STROKE_THICKNESS_FACTOR = 0.15;
|
|
47
|
-
var ARROW_TIP_OFFSET_FACTOR = 0.3;
|
|
48
|
-
var MOTION_DURATION = 150;
|
|
49
|
-
var RANK_LABELS = '12345678';
|
|
50
|
-
var FILE_LABELS = 'abcdefgh';
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* SVG image representing a chessboard diagram. Optionally, the user may interact with the board (move pieces, click on squares...).
|
|
54
|
-
* Annotations such as square markers or arrows can also be added to the board.
|
|
55
|
-
*/
|
|
56
|
-
var Chessboard = /*#__PURE__*/function (_React$Component) {
|
|
57
|
-
_inherits(Chessboard, _React$Component);
|
|
58
|
-
var _super = _createSuper(Chessboard);
|
|
59
|
-
function Chessboard(props) {
|
|
60
|
-
var _this;
|
|
61
|
-
_classCallCheck(this, Chessboard);
|
|
62
|
-
_this = _super.call(this, props);
|
|
63
|
-
_this.state = {
|
|
64
|
-
inhibitedSquare: '-',
|
|
65
|
-
draggedSquare: '-',
|
|
66
|
-
hoveredSquare: '-',
|
|
67
|
-
promotionDrawer: false,
|
|
68
|
-
windowWidth: window.innerWidth
|
|
69
|
-
};
|
|
70
|
-
_this.arrowTipIdSuffix = (0, _util.generateRandomId)();
|
|
71
|
-
return _this;
|
|
72
|
-
}
|
|
73
|
-
_createClass(Chessboard, [{
|
|
74
|
-
key: "componentDidMount",
|
|
75
|
-
value: function componentDidMount() {
|
|
76
|
-
var _this2 = this;
|
|
77
|
-
this.windowResizeListener = function () {
|
|
78
|
-
return _this2.handleWindowResize();
|
|
79
|
-
};
|
|
80
|
-
window.addEventListener('resize', this.windowResizeListener);
|
|
81
|
-
}
|
|
82
|
-
}, {
|
|
83
|
-
key: "componentWillUnmount",
|
|
84
|
-
value: function componentWillUnmount() {
|
|
85
|
-
if (this.windowResizeListener) {
|
|
86
|
-
window.removeEventListener('resize', this.windowResizeListener);
|
|
87
|
-
this.windowResizeListener = null;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}, {
|
|
91
|
-
key: "render",
|
|
92
|
-
value: function render() {
|
|
93
|
-
var _this3 = this;
|
|
94
|
-
// Compute the current position.
|
|
95
|
-
var info = this.getPositionAndMoveInfo();
|
|
96
|
-
if (info.positionError) {
|
|
97
|
-
return /*#__PURE__*/_react["default"].createElement(_ErrorBox["default"], {
|
|
98
|
-
title: _i18n["default"].INVALID_FEN_ERROR_TITLE,
|
|
99
|
-
message: info.message
|
|
100
|
-
});
|
|
101
|
-
} else if (info.moveError) {
|
|
102
|
-
return /*#__PURE__*/_react["default"].createElement(_ErrorBox["default"], {
|
|
103
|
-
title: _i18n["default"].INVALID_NOTATION_ERROR_TITLE,
|
|
104
|
-
message: info.message
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
var position = info.position,
|
|
108
|
-
move = info.move,
|
|
109
|
-
positionBefore = info.positionBefore;
|
|
110
|
-
|
|
111
|
-
// Compute the attributes.
|
|
112
|
-
var squareSize = this.getSquareSize();
|
|
113
|
-
var coordinateVisible = this.isCoordinateVisible();
|
|
114
|
-
var fontSize = computeCoordinateFontSize(squareSize);
|
|
115
|
-
var colorset = _colorsets2["default"][this.props.colorset];
|
|
116
|
-
var pieceset = _piecesets2["default"][this.props.pieceset];
|
|
117
|
-
if (isNaN(squareSize) || !colorset || !pieceset) {
|
|
118
|
-
return undefined;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// Render the squares.
|
|
122
|
-
var squares = [];
|
|
123
|
-
(0, _kokopu.forEachSquare)(function (sq) {
|
|
124
|
-
return squares.push(_this3.renderSquare(squareSize, colorset, sq));
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
// Render coordinates.
|
|
128
|
-
var rankCoordinates = [];
|
|
129
|
-
var fileCoordinates = [];
|
|
130
|
-
if (coordinateVisible) {
|
|
131
|
-
for (var c = 0; c < 8; ++c) {
|
|
132
|
-
rankCoordinates.push(this.renderRankCoordinate(squareSize, fontSize, c));
|
|
133
|
-
fileCoordinates.push(this.renderFileCoordinate(squareSize, fontSize, c));
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// Render the whole canvas.
|
|
138
|
-
var xmin = coordinateVisible ? Math.round(-RANK_COORDINATE_WIDTH_FACTOR * fontSize) : 0;
|
|
139
|
-
var ymin = 0;
|
|
140
|
-
var xmax = 9 * squareSize + Math.round(TURN_FLAG_SPACING_FACTOR * squareSize);
|
|
141
|
-
var ymax = 8 * squareSize + (coordinateVisible ? Math.round(FILE_COORDINATE_HEIGHT_FACTOR * fontSize) : 0);
|
|
142
|
-
var viewBox = "".concat(xmin, " ").concat(ymin, " ").concat(xmax - xmin, " ").concat(ymax - ymin);
|
|
143
|
-
return /*#__PURE__*/_react["default"].createElement("svg", {
|
|
144
|
-
className: "kokopu-chessboard",
|
|
145
|
-
viewBox: viewBox,
|
|
146
|
-
width: xmax - xmin,
|
|
147
|
-
height: ymax - ymin
|
|
148
|
-
}, /*#__PURE__*/_react["default"].createElement("defs", null, this.renderArrowTip(colorset, 'b'), this.renderArrowTip(colorset, 'g'), this.renderArrowTip(colorset, 'r'), this.renderArrowTip(colorset, 'y')), squares, rankCoordinates, fileCoordinates, this.renderBoardContent(position, positionBefore, move, squareSize, colorset, pieceset));
|
|
149
|
-
}
|
|
150
|
-
}, {
|
|
151
|
-
key: "renderBoardContent",
|
|
152
|
-
value: function renderBoardContent(position, positionBefore, move, squareSize, colorset, pieceset) {
|
|
153
|
-
var _this4 = this;
|
|
154
|
-
if (move && this.props.animated) {
|
|
155
|
-
var key = positionBefore.variant() + '|' + positionBefore.fen() + '|' + move.toString();
|
|
156
|
-
return /*#__PURE__*/_react["default"].createElement(_Motion["default"], {
|
|
157
|
-
key: key,
|
|
158
|
-
duration: MOTION_DURATION
|
|
159
|
-
}, function (motionCursor) {
|
|
160
|
-
return motionCursor === 1 ? _this4.renderBoardContentStill(position, move, squareSize, colorset, pieceset) : _this4.renderBoardContentAnimated(positionBefore, move, motionCursor, squareSize, colorset, pieceset);
|
|
161
|
-
});
|
|
162
|
-
} else {
|
|
163
|
-
return this.renderBoardContentStill(position, move, squareSize, colorset, pieceset);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Render the board content during the animation.
|
|
169
|
-
*/
|
|
170
|
-
}, {
|
|
171
|
-
key: "renderBoardContentAnimated",
|
|
172
|
-
value: function renderBoardContentAnimated(positionBefore, move, motionCursor, squareSize, colorset, pieceset) {
|
|
173
|
-
var _this5 = this;
|
|
174
|
-
var pieces = [];
|
|
175
|
-
(0, _kokopu.forEachSquare)(function (sq) {
|
|
176
|
-
return pieces.push(_this5.renderPieceAnimated(positionBefore, move, motionCursor, squareSize, pieceset, sq));
|
|
177
|
-
});
|
|
178
|
-
return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, pieces, this.renderMoveArrow(move, motionCursor, squareSize, colorset), this.renderTurnFlag((0, _kokopu.oppositeColor)(positionBefore.turn()), squareSize, pieceset));
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* Render the board content when the animation has been completed (or if there is no animation).
|
|
183
|
-
*/
|
|
184
|
-
}, {
|
|
185
|
-
key: "renderBoardContentStill",
|
|
186
|
-
value: function renderBoardContentStill(position, move, squareSize, colorset, pieceset) {
|
|
187
|
-
var _this6 = this;
|
|
188
|
-
// Compute the annotations.
|
|
189
|
-
var sqm = parseMarkers(this.props.squareMarkers, _markers.parseSquareMarkers, _util.isValidSquare, _util.isValidColor);
|
|
190
|
-
var txtm = parseMarkers(this.props.textMarkers, _markers.parseTextMarkers, _util.isValidSquare, function (value) {
|
|
191
|
-
return value && (0, _util.isValidSymbol)(value.symbol) && (0, _util.isValidColor)(value.color);
|
|
192
|
-
});
|
|
193
|
-
var arm = parseMarkers(this.props.arrowMarkers, _markers.parseArrowMarkers, _util.isValidVector, _util.isValidColor);
|
|
194
|
-
|
|
195
|
-
// Render the square-related objects.
|
|
196
|
-
var pieces = [];
|
|
197
|
-
var handles = [];
|
|
198
|
-
(0, _kokopu.forEachSquare)(function (sq) {
|
|
199
|
-
pieces.push(_this6.renderPiece(position, squareSize, pieceset, sq));
|
|
200
|
-
if (_this6.props.interactionMode) {
|
|
201
|
-
handles.push(_this6.renderSquareHandle(position, squareSize, sq));
|
|
202
|
-
}
|
|
203
|
-
});
|
|
204
|
-
return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, this.renderSquareMarkers(sqm, squareSize, colorset), this.renderHoveredSquare(squareSize, colorset), pieces, this.renderTextMarkers(txtm, squareSize, colorset), this.renderArrowMarkers(arm, squareSize, colorset), this.renderMoveArrow(move, 1, squareSize, colorset), handles, this.renderPromotionDrawer(position, squareSize, colorset, pieceset), this.renderDraggedPiece(position, squareSize, pieceset), this.renderDraggedArrow(squareSize, colorset), this.renderTurnFlag(position.turn(), squareSize, pieceset));
|
|
205
|
-
}
|
|
206
|
-
}, {
|
|
207
|
-
key: "renderSquare",
|
|
208
|
-
value: function renderSquare(squareSize, colorset, sq) {
|
|
209
|
-
var _this$getSquareCoordi = this.getSquareCoordinates(squareSize, sq),
|
|
210
|
-
x = _this$getSquareCoordi.x,
|
|
211
|
-
y = _this$getSquareCoordi.y;
|
|
212
|
-
return /*#__PURE__*/_react["default"].createElement("rect", {
|
|
213
|
-
key: sq,
|
|
214
|
-
x: x,
|
|
215
|
-
y: y,
|
|
216
|
-
width: squareSize,
|
|
217
|
-
height: squareSize,
|
|
218
|
-
fill: colorset[(0, _kokopu.squareColor)(sq)]
|
|
219
|
-
});
|
|
220
|
-
}
|
|
221
|
-
}, {
|
|
222
|
-
key: "renderHoveredSquare",
|
|
223
|
-
value: function renderHoveredSquare(squareSize, colorset) {
|
|
224
|
-
if (this.state.hoveredSquare === '-') {
|
|
225
|
-
return undefined;
|
|
226
|
-
}
|
|
227
|
-
var _this$getSquareCoordi2 = this.getSquareCoordinates(squareSize, this.state.hoveredSquare),
|
|
228
|
-
x = _this$getSquareCoordi2.x,
|
|
229
|
-
y = _this$getSquareCoordi2.y;
|
|
230
|
-
var thickness = Math.max(2, Math.round(HOVER_MARKER_THICKNESS_FACTOR * squareSize));
|
|
231
|
-
var size = squareSize - thickness;
|
|
232
|
-
var color = this.isEditArrowModeEnabled() ? this.props.editedArrowColor : this.props.moveArrowColor;
|
|
233
|
-
return /*#__PURE__*/_react["default"].createElement("rect", {
|
|
234
|
-
className: "kokopu-hoveredSquare",
|
|
235
|
-
x: x + thickness / 2,
|
|
236
|
-
y: y + thickness / 2,
|
|
237
|
-
width: size,
|
|
238
|
-
height: size,
|
|
239
|
-
stroke: colorset['c' + color],
|
|
240
|
-
strokeWidth: thickness
|
|
241
|
-
});
|
|
242
|
-
}
|
|
243
|
-
}, {
|
|
244
|
-
key: "renderPiece",
|
|
245
|
-
value: function renderPiece(position, squareSize, pieceset, sq) {
|
|
246
|
-
var cp = position.square(sq);
|
|
247
|
-
if (cp === '-' || this.state.inhibitedSquare === sq) {
|
|
248
|
-
return undefined;
|
|
249
|
-
}
|
|
250
|
-
var _this$getSquareCoordi3 = this.getSquareCoordinates(squareSize, sq),
|
|
251
|
-
x = _this$getSquareCoordi3.x,
|
|
252
|
-
y = _this$getSquareCoordi3.y;
|
|
253
|
-
return /*#__PURE__*/_react["default"].createElement("image", {
|
|
254
|
-
key: 'piece-' + sq,
|
|
255
|
-
x: x,
|
|
256
|
-
y: y,
|
|
257
|
-
width: squareSize,
|
|
258
|
-
height: squareSize,
|
|
259
|
-
href: pieceset[cp]
|
|
260
|
-
});
|
|
261
|
-
}
|
|
262
|
-
}, {
|
|
263
|
-
key: "renderPieceAnimated",
|
|
264
|
-
value: function renderPieceAnimated(positionBefore, move, motionCursor, squareSize, pieceset, sq) {
|
|
265
|
-
var cp = positionBefore.square(sq);
|
|
266
|
-
if (cp === '-' || move.to() === sq || move.isEnPassant() && move.enPassantSquare() === sq) {
|
|
267
|
-
return undefined;
|
|
268
|
-
}
|
|
269
|
-
var _this$getSquareCoordi4 = this.getSquareCoordinates(squareSize, sq),
|
|
270
|
-
x = _this$getSquareCoordi4.x,
|
|
271
|
-
y = _this$getSquareCoordi4.y;
|
|
272
|
-
if (sq === move.from()) {
|
|
273
|
-
var _this$getSquareCoordi5 = this.getSquareCoordinates(squareSize, move.to()),
|
|
274
|
-
xTo = _this$getSquareCoordi5.x,
|
|
275
|
-
yTo = _this$getSquareCoordi5.y;
|
|
276
|
-
x = xTo * motionCursor + x * (1 - motionCursor);
|
|
277
|
-
y = yTo * motionCursor + y * (1 - motionCursor);
|
|
278
|
-
if (move.isPromotion() && motionCursor > 0.8) {
|
|
279
|
-
cp = move.coloredPromotion();
|
|
280
|
-
}
|
|
281
|
-
} else if (move.isCastling() && sq === move.rookFrom()) {
|
|
282
|
-
var _this$getSquareCoordi6 = this.getSquareCoordinates(squareSize, move.rookTo()),
|
|
283
|
-
_xTo = _this$getSquareCoordi6.x,
|
|
284
|
-
_yTo = _this$getSquareCoordi6.y;
|
|
285
|
-
x = _xTo * motionCursor + x * (1 - motionCursor);
|
|
286
|
-
y = _yTo * motionCursor + y * (1 - motionCursor);
|
|
287
|
-
}
|
|
288
|
-
return /*#__PURE__*/_react["default"].createElement("image", {
|
|
289
|
-
key: 'piece-' + sq,
|
|
290
|
-
x: x,
|
|
291
|
-
y: y,
|
|
292
|
-
width: squareSize,
|
|
293
|
-
height: squareSize,
|
|
294
|
-
href: pieceset[cp]
|
|
295
|
-
});
|
|
296
|
-
}
|
|
297
|
-
}, {
|
|
298
|
-
key: "renderDraggedPiece",
|
|
299
|
-
value: function renderDraggedPiece(position, squareSize, pieceset) {
|
|
300
|
-
if (!(this.isMovePieceModeEnabled() || this.isPlayMoveModeEnabled()) || this.state.draggedSquare === '-') {
|
|
301
|
-
return undefined;
|
|
302
|
-
}
|
|
303
|
-
var _this$getSquareCoordi7 = this.getSquareCoordinates(squareSize, this.state.draggedSquare),
|
|
304
|
-
x = _this$getSquareCoordi7.x,
|
|
305
|
-
y = _this$getSquareCoordi7.y;
|
|
306
|
-
x = Math.min(Math.max(x + this.state.dragPosition.x, 0), 7 * squareSize);
|
|
307
|
-
y = Math.min(Math.max(y + this.state.dragPosition.y, 0), 7 * squareSize);
|
|
308
|
-
var cp = position.square(this.state.draggedSquare);
|
|
309
|
-
return /*#__PURE__*/_react["default"].createElement("image", {
|
|
310
|
-
className: "kokopu-pieceDraggable kokopu-dragging",
|
|
311
|
-
x: x,
|
|
312
|
-
y: y,
|
|
313
|
-
width: squareSize,
|
|
314
|
-
height: squareSize,
|
|
315
|
-
href: pieceset[cp]
|
|
316
|
-
});
|
|
317
|
-
}
|
|
318
|
-
}, {
|
|
319
|
-
key: "renderDraggedArrow",
|
|
320
|
-
value: function renderDraggedArrow(squareSize, colorset) {
|
|
321
|
-
if (!this.isEditArrowModeEnabled() || this.state.draggedSquare === '-') {
|
|
322
|
-
return undefined;
|
|
323
|
-
}
|
|
324
|
-
var strokeWidth = squareSize * STROKE_THICKNESS_FACTOR;
|
|
325
|
-
var arrowTipId = this.getArrowTipId(this.props.editedArrowColor);
|
|
326
|
-
var _this$getSquareCoordi8 = this.getSquareCoordinates(squareSize, this.state.draggedSquare),
|
|
327
|
-
x = _this$getSquareCoordi8.x,
|
|
328
|
-
y = _this$getSquareCoordi8.y;
|
|
329
|
-
var xFrom = x + squareSize / 2;
|
|
330
|
-
var yFrom = y + squareSize / 2;
|
|
331
|
-
var xTo = Math.min(Math.max(x + this.state.dragPosition.x + this.state.cursorOffset.x, squareSize / 2), 15 * squareSize / 2);
|
|
332
|
-
var yTo = Math.min(Math.max(y + this.state.dragPosition.y + this.state.cursorOffset.y, squareSize / 2), 15 * squareSize / 2);
|
|
333
|
-
return /*#__PURE__*/_react["default"].createElement("line", {
|
|
334
|
-
className: "kokopu-annotation kokopu-arrow kokopu-arrowDraggable kokopu-dragging",
|
|
335
|
-
x1: xFrom,
|
|
336
|
-
y1: yFrom,
|
|
337
|
-
x2: xTo,
|
|
338
|
-
y2: yTo,
|
|
339
|
-
stroke: colorset['c' + this.props.editedArrowColor],
|
|
340
|
-
strokeWidth: strokeWidth,
|
|
341
|
-
markerEnd: "url(#".concat(arrowTipId, ")")
|
|
342
|
-
});
|
|
343
|
-
}
|
|
344
|
-
}, {
|
|
345
|
-
key: "renderPromotionDrawer",
|
|
346
|
-
value: function renderPromotionDrawer(position, squareSize, colorset, pieceset) {
|
|
347
|
-
var _this7 = this;
|
|
348
|
-
if (!this.state.promotionDrawer) {
|
|
349
|
-
return undefined;
|
|
350
|
-
}
|
|
351
|
-
var _this$getSquareCoordi9 = this.getSquareCoordinates(squareSize, this.state.promotionDrawer.origin),
|
|
352
|
-
x = _this$getSquareCoordi9.x,
|
|
353
|
-
y = _this$getSquareCoordi9.y;
|
|
354
|
-
var inverted = position.turn() === (this.props.flipped ? 'w' : 'b'); // false==top-to-bottom true==bottom-to-top
|
|
355
|
-
var y0 = inverted ? y - squareSize * (this.state.promotionDrawer.buttons.length - 1) : y;
|
|
356
|
-
var buttons = this.state.promotionDrawer.buttons.map(function (p, i) {
|
|
357
|
-
var cp = position.turn() + p;
|
|
358
|
-
return /*#__PURE__*/_react["default"].createElement("image", {
|
|
359
|
-
key: 'drawer-piece-' + p,
|
|
360
|
-
className: "kokopu-clickable",
|
|
361
|
-
x: x,
|
|
362
|
-
y: y + i * (inverted ? -squareSize : squareSize),
|
|
363
|
-
width: squareSize,
|
|
364
|
-
height: squareSize,
|
|
365
|
-
href: pieceset[cp],
|
|
366
|
-
onClick: function onClick() {
|
|
367
|
-
return _this7.handleDrawerButtonClicked(p);
|
|
368
|
-
}
|
|
369
|
-
});
|
|
370
|
-
});
|
|
371
|
-
return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("rect", {
|
|
372
|
-
className: "kokopu-handle",
|
|
373
|
-
x: 0,
|
|
374
|
-
y: 0,
|
|
375
|
-
width: squareSize * 8,
|
|
376
|
-
height: squareSize * 8,
|
|
377
|
-
onClick: function onClick() {
|
|
378
|
-
return _this7.handleDrawerCancelButtonClicked();
|
|
379
|
-
}
|
|
380
|
-
}), /*#__PURE__*/_react["default"].createElement("rect", {
|
|
381
|
-
x: x,
|
|
382
|
-
y: y0,
|
|
383
|
-
width: squareSize,
|
|
384
|
-
height: squareSize * this.state.promotionDrawer.buttons.length,
|
|
385
|
-
fill: colorset.b
|
|
386
|
-
}), /*#__PURE__*/_react["default"].createElement("rect", {
|
|
387
|
-
x: x,
|
|
388
|
-
y: y0,
|
|
389
|
-
width: squareSize,
|
|
390
|
-
height: squareSize * this.state.promotionDrawer.buttons.length,
|
|
391
|
-
className: "kokopu-drawerMask",
|
|
392
|
-
fill: colorset.w
|
|
393
|
-
}), buttons);
|
|
394
|
-
}
|
|
395
|
-
}, {
|
|
396
|
-
key: "renderSquareHandle",
|
|
397
|
-
value: function renderSquareHandle(position, squareSize, sq) {
|
|
398
|
-
var _this8 = this;
|
|
399
|
-
var _this$getSquareCoordi10 = this.getSquareCoordinates(squareSize, sq),
|
|
400
|
-
x = _this$getSquareCoordi10.x,
|
|
401
|
-
y = _this$getSquareCoordi10.y;
|
|
402
|
-
var dragEnabledForMovePieces = this.isMovePieceModeEnabled() && position.square(sq) !== '-';
|
|
403
|
-
var dragEnabledForEditArrows = this.isEditArrowModeEnabled();
|
|
404
|
-
var dragEnabledForPlayMoves = this.isPlayMoveModeEnabled() && position.isLegal() && position.square(sq).startsWith(position.turn()) && !this.state.promotionDrawer;
|
|
405
|
-
if (dragEnabledForMovePieces || dragEnabledForEditArrows || dragEnabledForPlayMoves) {
|
|
406
|
-
return /*#__PURE__*/_react["default"].createElement(_DraggableHandle["default"], {
|
|
407
|
-
key: 'handle-' + sq,
|
|
408
|
-
x: x,
|
|
409
|
-
y: y,
|
|
410
|
-
width: squareSize,
|
|
411
|
-
height: squareSize,
|
|
412
|
-
isArrowHandle: this.isEditArrowModeEnabled(),
|
|
413
|
-
onDragStart: function onDragStart(x0, y0) {
|
|
414
|
-
return _this8.handleDragStart(sq, x0, y0);
|
|
415
|
-
},
|
|
416
|
-
onDrag: function onDrag(dx, dy) {
|
|
417
|
-
return _this8.handleDrag(sq, dx, dy);
|
|
418
|
-
},
|
|
419
|
-
onDragStop: function onDragStop(dx, dy) {
|
|
420
|
-
return _this8.handleDragStop(sq, dx, dy);
|
|
421
|
-
},
|
|
422
|
-
onDragCanceled: function onDragCanceled() {
|
|
423
|
-
return _this8.handleDragCanceled();
|
|
424
|
-
}
|
|
425
|
-
});
|
|
426
|
-
} else if (this.props.interactionMode === 'clickSquares') {
|
|
427
|
-
return /*#__PURE__*/_react["default"].createElement("rect", {
|
|
428
|
-
key: 'handle-' + sq,
|
|
429
|
-
className: "kokopu-handle kokopu-clickable",
|
|
430
|
-
x: x,
|
|
431
|
-
y: y,
|
|
432
|
-
width: squareSize,
|
|
433
|
-
height: squareSize,
|
|
434
|
-
onClick: function onClick() {
|
|
435
|
-
return _this8.handleSquareClicked(sq);
|
|
436
|
-
}
|
|
437
|
-
});
|
|
438
|
-
} else {
|
|
439
|
-
return undefined;
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
}, {
|
|
443
|
-
key: "renderSquareMarkers",
|
|
444
|
-
value: function renderSquareMarkers(sqm, squareSize, colorset) {
|
|
445
|
-
var _this9 = this;
|
|
446
|
-
var result = [];
|
|
447
|
-
Object.entries(sqm).forEach(function (_ref) {
|
|
448
|
-
var _ref2 = _slicedToArray(_ref, 2),
|
|
449
|
-
sq = _ref2[0],
|
|
450
|
-
color = _ref2[1];
|
|
451
|
-
var _this9$getSquareCoord = _this9.getSquareCoordinates(squareSize, sq),
|
|
452
|
-
x = _this9$getSquareCoord.x,
|
|
453
|
-
y = _this9$getSquareCoord.y;
|
|
454
|
-
result.push( /*#__PURE__*/_react["default"].createElement("rect", {
|
|
455
|
-
key: 'sqm-' + sq,
|
|
456
|
-
className: "kokopu-annotation",
|
|
457
|
-
x: x,
|
|
458
|
-
y: y,
|
|
459
|
-
width: squareSize,
|
|
460
|
-
height: squareSize,
|
|
461
|
-
fill: colorset['c' + color]
|
|
462
|
-
}));
|
|
463
|
-
});
|
|
464
|
-
return result;
|
|
465
|
-
}
|
|
466
|
-
}, {
|
|
467
|
-
key: "renderTextMarkers",
|
|
468
|
-
value: function renderTextMarkers(txtm, squareSize, colorset) {
|
|
469
|
-
var _this10 = this;
|
|
470
|
-
var result = [];
|
|
471
|
-
Object.entries(txtm).forEach(function (_ref3) {
|
|
472
|
-
var _ref4 = _slicedToArray(_ref3, 2),
|
|
473
|
-
sq = _ref4[0],
|
|
474
|
-
value = _ref4[1];
|
|
475
|
-
var _this10$getSquareCoor = _this10.getSquareCoordinates(squareSize, sq),
|
|
476
|
-
x = _this10$getSquareCoor.x,
|
|
477
|
-
y = _this10$getSquareCoor.y;
|
|
478
|
-
x += squareSize / 2;
|
|
479
|
-
y += squareSize / 2;
|
|
480
|
-
result.push( /*#__PURE__*/_react["default"].createElement("g", {
|
|
481
|
-
key: 'txtm-' + sq,
|
|
482
|
-
className: "kokopu-annotation"
|
|
483
|
-
}, /*#__PURE__*/_react["default"].createElement(_TextSymbol["default"], {
|
|
484
|
-
x: x,
|
|
485
|
-
y: y,
|
|
486
|
-
size: squareSize,
|
|
487
|
-
symbol: value.symbol,
|
|
488
|
-
color: colorset['c' + value.color]
|
|
489
|
-
})));
|
|
490
|
-
});
|
|
491
|
-
return result;
|
|
492
|
-
}
|
|
493
|
-
}, {
|
|
494
|
-
key: "renderArrowMarkers",
|
|
495
|
-
value: function renderArrowMarkers(arm, squareSize, colorset) {
|
|
496
|
-
var _this11 = this;
|
|
497
|
-
var result = [];
|
|
498
|
-
var strokeWidth = squareSize * STROKE_THICKNESS_FACTOR;
|
|
499
|
-
Object.entries(arm).forEach(function (_ref5) {
|
|
500
|
-
var _ref6 = _slicedToArray(_ref5, 2),
|
|
501
|
-
vect = _ref6[0],
|
|
502
|
-
color = _ref6[1];
|
|
503
|
-
var from = vect.substring(0, 2);
|
|
504
|
-
var to = vect.substring(2, 4);
|
|
505
|
-
if (from === to) {
|
|
506
|
-
return;
|
|
507
|
-
}
|
|
508
|
-
var _this11$getSquareCoor = _this11.getSquareCoordinates(squareSize, from),
|
|
509
|
-
xFrom = _this11$getSquareCoor.x,
|
|
510
|
-
yFrom = _this11$getSquareCoor.y;
|
|
511
|
-
var _this11$getSquareCoor2 = _this11.getSquareCoordinates(squareSize, to),
|
|
512
|
-
xTo = _this11$getSquareCoor2.x,
|
|
513
|
-
yTo = _this11$getSquareCoor2.y;
|
|
514
|
-
xFrom += squareSize / 2;
|
|
515
|
-
yFrom += squareSize / 2;
|
|
516
|
-
xTo += squareSize / 2;
|
|
517
|
-
yTo += squareSize / 2;
|
|
518
|
-
xTo += Math.sign(xFrom - xTo) * ARROW_TIP_OFFSET_FACTOR * squareSize;
|
|
519
|
-
yTo += Math.sign(yFrom - yTo) * ARROW_TIP_OFFSET_FACTOR * squareSize;
|
|
520
|
-
var arrowTipId = _this11.getArrowTipId(color);
|
|
521
|
-
result.push( /*#__PURE__*/_react["default"].createElement("line", {
|
|
522
|
-
key: 'arm-' + vect,
|
|
523
|
-
className: "kokopu-annotation kokopu-arrow",
|
|
524
|
-
x1: xFrom,
|
|
525
|
-
y1: yFrom,
|
|
526
|
-
x2: xTo,
|
|
527
|
-
y2: yTo,
|
|
528
|
-
stroke: colorset['c' + color],
|
|
529
|
-
strokeWidth: strokeWidth,
|
|
530
|
-
markerEnd: "url(#".concat(arrowTipId, ")")
|
|
531
|
-
}));
|
|
532
|
-
});
|
|
533
|
-
return result;
|
|
534
|
-
}
|
|
535
|
-
}, {
|
|
536
|
-
key: "renderMoveArrow",
|
|
537
|
-
value: function renderMoveArrow(move, motionCursor, squareSize, colorset) {
|
|
538
|
-
if (!move || motionCursor < 0.1 || !this.props.moveArrowVisible || move.from() === move.to()) {
|
|
539
|
-
return undefined;
|
|
540
|
-
}
|
|
541
|
-
var _this$getSquareCoordi11 = this.getSquareCoordinates(squareSize, move.from()),
|
|
542
|
-
xFrom = _this$getSquareCoordi11.x,
|
|
543
|
-
yFrom = _this$getSquareCoordi11.y;
|
|
544
|
-
xFrom += squareSize / 2;
|
|
545
|
-
yFrom += squareSize / 2;
|
|
546
|
-
var _this$getSquareCoordi12 = this.getSquareCoordinates(squareSize, move.to()),
|
|
547
|
-
xTo = _this$getSquareCoordi12.x,
|
|
548
|
-
yTo = _this$getSquareCoordi12.y;
|
|
549
|
-
xTo += squareSize / 2;
|
|
550
|
-
yTo += squareSize / 2;
|
|
551
|
-
xTo += Math.sign(xFrom - xTo) * ARROW_TIP_OFFSET_FACTOR * squareSize;
|
|
552
|
-
yTo += Math.sign(yFrom - yTo) * ARROW_TIP_OFFSET_FACTOR * squareSize;
|
|
553
|
-
var x = xTo * motionCursor + xFrom * (1 - motionCursor);
|
|
554
|
-
var y = yTo * motionCursor + yFrom * (1 - motionCursor);
|
|
555
|
-
var color = this.props.moveArrowColor;
|
|
556
|
-
return /*#__PURE__*/_react["default"].createElement("line", {
|
|
557
|
-
className: "kokopu-annotation kokopu-arrow",
|
|
558
|
-
x1: xFrom,
|
|
559
|
-
y1: yFrom,
|
|
560
|
-
x2: x,
|
|
561
|
-
y2: y,
|
|
562
|
-
stroke: colorset['c' + color],
|
|
563
|
-
strokeWidth: squareSize * STROKE_THICKNESS_FACTOR,
|
|
564
|
-
markerEnd: "url(#".concat(this.getArrowTipId(color), ")")
|
|
565
|
-
});
|
|
566
|
-
}
|
|
567
|
-
}, {
|
|
568
|
-
key: "renderArrowTip",
|
|
569
|
-
value: function renderArrowTip(colorset, color) {
|
|
570
|
-
return /*#__PURE__*/_react["default"].createElement(_ArrowTip["default"], {
|
|
571
|
-
id: this.getArrowTipId(color),
|
|
572
|
-
color: colorset['c' + color]
|
|
573
|
-
});
|
|
574
|
-
}
|
|
575
|
-
}, {
|
|
576
|
-
key: "renderTurnFlag",
|
|
577
|
-
value: function renderTurnFlag(turn, squareSize, pieceset) {
|
|
578
|
-
var x = 8 * squareSize + Math.round(TURN_FLAG_SPACING_FACTOR * squareSize);
|
|
579
|
-
var y = turn === (this.props.flipped ? 'b' : 'w') ? 7 * squareSize : 0;
|
|
580
|
-
return /*#__PURE__*/_react["default"].createElement("image", {
|
|
581
|
-
key: 'turn-' + turn,
|
|
582
|
-
x: x,
|
|
583
|
-
y: y,
|
|
584
|
-
width: squareSize,
|
|
585
|
-
height: squareSize,
|
|
586
|
-
href: pieceset[turn + 'x']
|
|
587
|
-
});
|
|
588
|
-
}
|
|
589
|
-
}, {
|
|
590
|
-
key: "renderRankCoordinate",
|
|
591
|
-
value: function renderRankCoordinate(squareSize, fontSize, rank) {
|
|
592
|
-
var x = Math.round(-RANK_COORDINATE_WIDTH_FACTOR * fontSize) / 2;
|
|
593
|
-
var y = (this.props.flipped ? rank + 0.5 : 7.5 - rank) * squareSize;
|
|
594
|
-
var label = RANK_LABELS[rank];
|
|
595
|
-
return /*#__PURE__*/_react["default"].createElement("text", {
|
|
596
|
-
key: 'rank-' + label,
|
|
597
|
-
className: "kokopu-coordinate",
|
|
598
|
-
x: x,
|
|
599
|
-
y: y,
|
|
600
|
-
fontSize: fontSize
|
|
601
|
-
}, label);
|
|
602
|
-
}
|
|
603
|
-
}, {
|
|
604
|
-
key: "renderFileCoordinate",
|
|
605
|
-
value: function renderFileCoordinate(squareSize, fontSize, file) {
|
|
606
|
-
var x = (this.props.flipped ? 7.5 - file : 0.5 + file) * squareSize;
|
|
607
|
-
var y = 8 * squareSize + Math.round(FILE_COORDINATE_HEIGHT_FACTOR * fontSize) / 2;
|
|
608
|
-
var label = FILE_LABELS[file];
|
|
609
|
-
return /*#__PURE__*/_react["default"].createElement("text", {
|
|
610
|
-
key: 'file-' + label,
|
|
611
|
-
className: "kokopu-coordinate",
|
|
612
|
-
x: x,
|
|
613
|
-
y: y,
|
|
614
|
-
fontSize: fontSize
|
|
615
|
-
}, label);
|
|
616
|
-
}
|
|
617
|
-
}, {
|
|
618
|
-
key: "handleWindowResize",
|
|
619
|
-
value: function handleWindowResize() {
|
|
620
|
-
this.setState({
|
|
621
|
-
windowWidth: window.innerWidth
|
|
622
|
-
});
|
|
623
|
-
}
|
|
624
|
-
}, {
|
|
625
|
-
key: "handleDragStart",
|
|
626
|
-
value: function handleDragStart(sq, x0, y0) {
|
|
627
|
-
this.setState({
|
|
628
|
-
inhibitedSquare: this.isMovePieceModeEnabled() || this.isPlayMoveModeEnabled() ? sq : '-',
|
|
629
|
-
draggedSquare: sq,
|
|
630
|
-
hoveredSquare: sq,
|
|
631
|
-
cursorOffset: {
|
|
632
|
-
x: x0,
|
|
633
|
-
y: y0
|
|
634
|
-
},
|
|
635
|
-
dragPosition: {
|
|
636
|
-
x: 0,
|
|
637
|
-
y: 0
|
|
638
|
-
}
|
|
639
|
-
});
|
|
640
|
-
}
|
|
641
|
-
}, {
|
|
642
|
-
key: "handleDrag",
|
|
643
|
-
value: function handleDrag(sq, dx, dy) {
|
|
644
|
-
var squareSize = this.getSquareSize();
|
|
645
|
-
var _this$getSquareCoordi13 = this.getSquareCoordinates(squareSize, sq),
|
|
646
|
-
x = _this$getSquareCoordi13.x,
|
|
647
|
-
y = _this$getSquareCoordi13.y;
|
|
648
|
-
var targetSq = this.getSquareAt(squareSize, x + dx + this.state.cursorOffset.x, y + dy + this.state.cursorOffset.y);
|
|
649
|
-
this.setState({
|
|
650
|
-
hoveredSquare: targetSq,
|
|
651
|
-
dragPosition: {
|
|
652
|
-
x: dx,
|
|
653
|
-
y: dy
|
|
654
|
-
}
|
|
655
|
-
});
|
|
656
|
-
}
|
|
657
|
-
}, {
|
|
658
|
-
key: "handleDragStop",
|
|
659
|
-
value: function handleDragStop(sq, dx, dy) {
|
|
660
|
-
var squareSize = this.getSquareSize();
|
|
661
|
-
var _this$getSquareCoordi14 = this.getSquareCoordinates(squareSize, sq),
|
|
662
|
-
x = _this$getSquareCoordi14.x,
|
|
663
|
-
y = _this$getSquareCoordi14.y;
|
|
664
|
-
var targetSq = this.getSquareAt(squareSize, x + dx + this.state.cursorOffset.x, y + dy + this.state.cursorOffset.y);
|
|
665
|
-
this.setState({
|
|
666
|
-
inhibitedSquare: '-',
|
|
667
|
-
draggedSquare: '-',
|
|
668
|
-
hoveredSquare: '-'
|
|
669
|
-
});
|
|
670
|
-
if (sq === targetSq || targetSq === '-') {
|
|
671
|
-
return;
|
|
672
|
-
}
|
|
673
|
-
if (this.isMovePieceModeEnabled() && this.props.onPieceMoved) {
|
|
674
|
-
this.props.onPieceMoved(sq, targetSq);
|
|
675
|
-
} else if (this.isEditArrowModeEnabled() && this.props.onArrowEdited) {
|
|
676
|
-
this.props.onArrowEdited(sq, targetSq);
|
|
677
|
-
} else if (this.isPlayMoveModeEnabled()) {
|
|
678
|
-
var _this$getPositionAndM = this.getPositionAndMoveInfo(),
|
|
679
|
-
position = _this$getPositionAndM.position;
|
|
680
|
-
var info = position.isMoveLegal(sq, targetSq);
|
|
681
|
-
if (!info) {
|
|
682
|
-
return;
|
|
683
|
-
}
|
|
684
|
-
switch (info.status) {
|
|
685
|
-
// Regular move.
|
|
686
|
-
case 'regular':
|
|
687
|
-
if (this.props.onMovePlayed) {
|
|
688
|
-
this.props.onMovePlayed(position.notation(info()));
|
|
689
|
-
}
|
|
690
|
-
break;
|
|
691
|
-
|
|
692
|
-
// Promotion move.
|
|
693
|
-
case 'promotion':
|
|
694
|
-
this.setState({
|
|
695
|
-
inhibitedSquare: sq,
|
|
696
|
-
promotionDrawer: {
|
|
697
|
-
origin: targetSq,
|
|
698
|
-
buttons: position.variant() === 'antichess' ? ['q', 'r', 'b', 'n', 'k'] : ['q', 'r', 'b', 'n'],
|
|
699
|
-
builder: function builder(piece) {
|
|
700
|
-
return position.notation(info(piece));
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
});
|
|
704
|
-
break;
|
|
705
|
-
|
|
706
|
-
// Other cases are not supposed to happen.
|
|
707
|
-
// istanbul ignore next
|
|
708
|
-
default:
|
|
709
|
-
break;
|
|
710
|
-
}
|
|
711
|
-
}
|
|
712
|
-
}
|
|
713
|
-
}, {
|
|
714
|
-
key: "handleDragCanceled",
|
|
715
|
-
value: function handleDragCanceled() {
|
|
716
|
-
this.setState({
|
|
717
|
-
inhibitedSquare: '-',
|
|
718
|
-
draggedSquare: '-',
|
|
719
|
-
hoveredSquare: '-'
|
|
720
|
-
});
|
|
721
|
-
}
|
|
722
|
-
}, {
|
|
723
|
-
key: "handleDrawerCancelButtonClicked",
|
|
724
|
-
value: function handleDrawerCancelButtonClicked() {
|
|
725
|
-
this.setState({
|
|
726
|
-
inhibitedSquare: '-',
|
|
727
|
-
promotionDrawer: false
|
|
728
|
-
});
|
|
729
|
-
}
|
|
730
|
-
}, {
|
|
731
|
-
key: "handleDrawerButtonClicked",
|
|
732
|
-
value: function handleDrawerButtonClicked(piece) {
|
|
733
|
-
var builder = this.state.promotionDrawer.builder;
|
|
734
|
-
this.setState({
|
|
735
|
-
inhibitedSquare: '-',
|
|
736
|
-
promotionDrawer: false
|
|
737
|
-
});
|
|
738
|
-
if (this.props.onMovePlayed) {
|
|
739
|
-
this.props.onMovePlayed(builder(piece));
|
|
740
|
-
}
|
|
741
|
-
}
|
|
742
|
-
}, {
|
|
743
|
-
key: "handleSquareClicked",
|
|
744
|
-
value: function handleSquareClicked(sq) {
|
|
745
|
-
if (this.props.onSquareClicked) {
|
|
746
|
-
this.props.onSquareClicked(sq);
|
|
747
|
-
}
|
|
748
|
-
}
|
|
749
|
-
|
|
750
|
-
/**
|
|
751
|
-
* Whether the "move piece" mode is enabled or not.
|
|
752
|
-
*/
|
|
753
|
-
}, {
|
|
754
|
-
key: "isMovePieceModeEnabled",
|
|
755
|
-
value: function isMovePieceModeEnabled() {
|
|
756
|
-
return this.props.interactionMode === 'movePieces';
|
|
757
|
-
}
|
|
758
|
-
|
|
759
|
-
/**
|
|
760
|
-
* Whether the "play move" mode is enabled or not.
|
|
761
|
-
*/
|
|
762
|
-
}, {
|
|
763
|
-
key: "isPlayMoveModeEnabled",
|
|
764
|
-
value: function isPlayMoveModeEnabled() {
|
|
765
|
-
return this.props.interactionMode === 'playMoves';
|
|
766
|
-
}
|
|
767
|
-
|
|
768
|
-
/**
|
|
769
|
-
* Whether the "edit arrow" mode is enabled or not.
|
|
770
|
-
*/
|
|
771
|
-
}, {
|
|
772
|
-
key: "isEditArrowModeEnabled",
|
|
773
|
-
value: function isEditArrowModeEnabled() {
|
|
774
|
-
return this.props.interactionMode === 'editArrows' && (0, _util.isValidColor)(this.props.editedArrowColor);
|
|
775
|
-
}
|
|
776
|
-
|
|
777
|
-
/**
|
|
778
|
-
* Return the (sanitized) square size.
|
|
779
|
-
*/
|
|
780
|
-
}, {
|
|
781
|
-
key: "getSquareSize",
|
|
782
|
-
value: function getSquareSize() {
|
|
783
|
-
var squareSize = (0, _util.sanitizeInteger)(this.props.squareSize, _util.MIN_SQUARE_SIZE, _util.MAX_SQUARE_SIZE);
|
|
784
|
-
var limit = computeSmallScreenLimits('squareSize', this.props.smallScreenLimits, this.state.windowWidth);
|
|
785
|
-
return isNaN(limit) ? squareSize : (0, _util.sanitizeInteger)(limit, _util.MIN_SQUARE_SIZE, squareSize);
|
|
786
|
-
}
|
|
787
|
-
|
|
788
|
-
/**
|
|
789
|
-
* Whether the file/rank coordinates are visible or not.
|
|
790
|
-
*/
|
|
791
|
-
}, {
|
|
792
|
-
key: "isCoordinateVisible",
|
|
793
|
-
value: function isCoordinateVisible() {
|
|
794
|
-
var limit = computeSmallScreenLimits('coordinateVisible', this.props.smallScreenLimits, this.state.windowWidth);
|
|
795
|
-
return this.props.coordinateVisible && (limit === undefined || limit);
|
|
796
|
-
}
|
|
797
|
-
|
|
798
|
-
/**
|
|
799
|
-
* Return the (x,y) coordinates of the given square in the SVG canvas.
|
|
800
|
-
*/
|
|
801
|
-
}, {
|
|
802
|
-
key: "getSquareCoordinates",
|
|
803
|
-
value: function getSquareCoordinates(squareSize, sq) {
|
|
804
|
-
var _squareToCoordinates = (0, _kokopu.squareToCoordinates)(sq),
|
|
805
|
-
file = _squareToCoordinates.file,
|
|
806
|
-
rank = _squareToCoordinates.rank;
|
|
807
|
-
var x = this.props.flipped ? (7 - file) * squareSize : file * squareSize;
|
|
808
|
-
var y = this.props.flipped ? rank * squareSize : (7 - rank) * squareSize;
|
|
809
|
-
return {
|
|
810
|
-
x: x,
|
|
811
|
-
y: y
|
|
812
|
-
};
|
|
813
|
-
}
|
|
814
|
-
|
|
815
|
-
/**
|
|
816
|
-
* Return information regarding the currently displayed position and move, or parsing error message if something went wrong.
|
|
817
|
-
*/
|
|
818
|
-
}, {
|
|
819
|
-
key: "getPositionAndMoveInfo",
|
|
820
|
-
value: function getPositionAndMoveInfo() {
|
|
821
|
-
// Parse the position.
|
|
822
|
-
var positionInfo = parsePosition(this.props.position);
|
|
823
|
-
if (positionInfo.error) {
|
|
824
|
-
return {
|
|
825
|
-
positionError: true,
|
|
826
|
-
moveError: true,
|
|
827
|
-
message: positionInfo.message
|
|
828
|
-
};
|
|
829
|
-
}
|
|
830
|
-
|
|
831
|
-
// Nothing else to do if no move is defined.
|
|
832
|
-
if (!this.props.move) {
|
|
833
|
-
return {
|
|
834
|
-
positionError: false,
|
|
835
|
-
moveError: false,
|
|
836
|
-
position: positionInfo.position
|
|
837
|
-
};
|
|
838
|
-
}
|
|
839
|
-
|
|
840
|
-
// Parse the move.
|
|
841
|
-
var moveInfo = parseMove(positionInfo.position, this.props.move);
|
|
842
|
-
if (moveInfo.error) {
|
|
843
|
-
return {
|
|
844
|
-
positionError: false,
|
|
845
|
-
moveError: true,
|
|
846
|
-
message: moveInfo.message,
|
|
847
|
-
positionBefore: positionInfo.position
|
|
848
|
-
};
|
|
849
|
-
}
|
|
850
|
-
|
|
851
|
-
// Compute the position after the move and return the result.
|
|
852
|
-
var positionAfter = new _kokopu.Position(positionInfo.position);
|
|
853
|
-
positionAfter.play(moveInfo.move);
|
|
854
|
-
return {
|
|
855
|
-
positionError: false,
|
|
856
|
-
moveError: false,
|
|
857
|
-
positionBefore: positionInfo.position,
|
|
858
|
-
move: moveInfo.move,
|
|
859
|
-
position: positionAfter
|
|
860
|
-
};
|
|
861
|
-
}
|
|
862
|
-
|
|
863
|
-
/**
|
|
864
|
-
* Return the square at the given location.
|
|
865
|
-
*/
|
|
866
|
-
}, {
|
|
867
|
-
key: "getSquareAt",
|
|
868
|
-
value: function getSquareAt(squareSize, x, y) {
|
|
869
|
-
var file = this.props.flipped ? 7 - Math.floor(x / squareSize) : Math.floor(x / squareSize);
|
|
870
|
-
var rank = this.props.flipped ? Math.floor(y / squareSize) : 7 - Math.floor(y / squareSize);
|
|
871
|
-
return file >= 0 && file < 8 && rank >= 0 && rank < 8 ? (0, _kokopu.coordinatesToSquare)(file, rank) : '-';
|
|
872
|
-
}
|
|
873
|
-
|
|
874
|
-
/**
|
|
875
|
-
* Return the DOM ID of an arrow tip with the given color.
|
|
876
|
-
*/
|
|
877
|
-
}, {
|
|
878
|
-
key: "getArrowTipId",
|
|
879
|
-
value: function getArrowTipId(color) {
|
|
880
|
-
return 'kokopu-arrowTip-' + color + '-' + this.arrowTipIdSuffix;
|
|
881
|
-
}
|
|
882
|
-
|
|
883
|
-
/**
|
|
884
|
-
* Return the size of the chessboard, assuming it is built with the given attributes.
|
|
885
|
-
*
|
|
886
|
-
* @param {number} squareSize
|
|
887
|
-
* @param {boolean} coordinateVisible
|
|
888
|
-
* @param {{width:number, squareSize:number, coordinateVisible:boolean}[]} smallScreenLimits
|
|
889
|
-
* @returns {{width:number, height:number}}
|
|
890
|
-
* @public
|
|
891
|
-
*/
|
|
892
|
-
}], [{
|
|
893
|
-
key: "size",
|
|
894
|
-
value: function size(squareSize, coordinateVisible, smallScreenLimits) {
|
|
895
|
-
// Enforce small-screen limits, if any.
|
|
896
|
-
if (typeof window !== 'undefined') {
|
|
897
|
-
var squareSizeLimit = computeSmallScreenLimits('squareSize', smallScreenLimits, window.innerWidth);
|
|
898
|
-
var coordinateVisibleLimit = computeSmallScreenLimits('coordinateVisible', smallScreenLimits, window.innerWidth);
|
|
899
|
-
if (!isNaN(squareSizeLimit)) {
|
|
900
|
-
squareSize = (0, _util.sanitizeInteger)(squareSizeLimit, _util.MIN_SQUARE_SIZE, squareSize);
|
|
901
|
-
}
|
|
902
|
-
coordinateVisible = coordinateVisible && (coordinateVisibleLimit === undefined || coordinateVisibleLimit);
|
|
903
|
-
}
|
|
904
|
-
|
|
905
|
-
// Compute the dimensions.
|
|
906
|
-
var width = 9 * squareSize + Math.round(TURN_FLAG_SPACING_FACTOR * squareSize);
|
|
907
|
-
var height = 8 * squareSize;
|
|
908
|
-
if (coordinateVisible) {
|
|
909
|
-
var fontSize = computeCoordinateFontSize(squareSize);
|
|
910
|
-
width += Math.round(RANK_COORDINATE_WIDTH_FACTOR * fontSize);
|
|
911
|
-
height += Math.round(FILE_COORDINATE_HEIGHT_FACTOR * fontSize);
|
|
912
|
-
}
|
|
913
|
-
return {
|
|
914
|
-
width: width,
|
|
915
|
-
height: height
|
|
916
|
-
};
|
|
917
|
-
}
|
|
918
|
-
|
|
919
|
-
/**
|
|
920
|
-
* Return the maximum square size that would allow the chessboard to fit in a rectangle of size `width x height`.
|
|
921
|
-
*
|
|
922
|
-
* @param {number} width
|
|
923
|
-
* @param {number} height
|
|
924
|
-
* @param {boolean} coordinateVisible
|
|
925
|
-
* @param {{width:number, squareSize:number, coordinateVisible:boolean}[]} smallScreenLimits
|
|
926
|
-
* @returns {number}
|
|
927
|
-
* @public
|
|
928
|
-
*/
|
|
929
|
-
}, {
|
|
930
|
-
key: "adaptSquareSize",
|
|
931
|
-
value: function adaptSquareSize(width, height, coordinateVisible, smallScreenLimits) {
|
|
932
|
-
var maxSquareSize = _util.MAX_SQUARE_SIZE;
|
|
933
|
-
|
|
934
|
-
// Enforce small-screen limits, if any.
|
|
935
|
-
if (typeof window !== 'undefined') {
|
|
936
|
-
var squareSizeLimit = computeSmallScreenLimits('squareSize', smallScreenLimits, window.innerWidth);
|
|
937
|
-
var coordinateVisibleLimit = computeSmallScreenLimits('coordinateVisible', smallScreenLimits, window.innerWidth);
|
|
938
|
-
if (!isNaN(squareSizeLimit)) {
|
|
939
|
-
maxSquareSize = (0, _util.sanitizeInteger)(squareSizeLimit, _util.MIN_SQUARE_SIZE, maxSquareSize);
|
|
940
|
-
}
|
|
941
|
-
coordinateVisible = coordinateVisible && (coordinateVisibleLimit === undefined || coordinateVisibleLimit);
|
|
942
|
-
}
|
|
943
|
-
function isAdapted(squareSize) {
|
|
944
|
-
var actualWidth = 9 * squareSize + Math.round(TURN_FLAG_SPACING_FACTOR * squareSize);
|
|
945
|
-
var actualHeight = 8 * squareSize;
|
|
946
|
-
if (coordinateVisible) {
|
|
947
|
-
var fontSize = computeCoordinateFontSize(squareSize);
|
|
948
|
-
actualWidth += Math.round(RANK_COORDINATE_WIDTH_FACTOR * fontSize);
|
|
949
|
-
actualHeight += Math.round(FILE_COORDINATE_HEIGHT_FACTOR * fontSize);
|
|
950
|
-
}
|
|
951
|
-
return actualWidth <= width && actualHeight <= height;
|
|
952
|
-
}
|
|
953
|
-
|
|
954
|
-
// Check min/max bounds.
|
|
955
|
-
if (isAdapted(maxSquareSize)) {
|
|
956
|
-
return maxSquareSize;
|
|
957
|
-
} else if (!isAdapted(_util.MIN_SQUARE_SIZE)) {
|
|
958
|
-
return _util.MIN_SQUARE_SIZE;
|
|
959
|
-
}
|
|
960
|
-
|
|
961
|
-
// Dichotomic search, between a (inclusive) and b (exclusive).
|
|
962
|
-
var a = _util.MIN_SQUARE_SIZE;
|
|
963
|
-
var b = maxSquareSize;
|
|
964
|
-
while (a + 1 < b) {
|
|
965
|
-
var mid = Math.floor((a + b) / 2);
|
|
966
|
-
if (isAdapted(mid)) {
|
|
967
|
-
a = mid;
|
|
968
|
-
} else {
|
|
969
|
-
b = mid;
|
|
970
|
-
}
|
|
971
|
-
}
|
|
972
|
-
return a;
|
|
973
|
-
}
|
|
974
|
-
|
|
975
|
-
/**
|
|
976
|
-
* Minimum square size (inclusive).
|
|
977
|
-
*
|
|
978
|
-
* @returns {number}
|
|
979
|
-
* @public
|
|
980
|
-
*/
|
|
981
|
-
}, {
|
|
982
|
-
key: "minSquareSize",
|
|
983
|
-
value: function minSquareSize() {
|
|
984
|
-
return _util.MIN_SQUARE_SIZE;
|
|
985
|
-
}
|
|
986
|
-
|
|
987
|
-
/**
|
|
988
|
-
* Maximum square size (inclusive).
|
|
989
|
-
*
|
|
990
|
-
* @returns {number}
|
|
991
|
-
* @public
|
|
992
|
-
*/
|
|
993
|
-
}, {
|
|
994
|
-
key: "maxSquareSize",
|
|
995
|
-
value: function maxSquareSize() {
|
|
996
|
-
return _util.MAX_SQUARE_SIZE;
|
|
997
|
-
}
|
|
998
|
-
|
|
999
|
-
/**
|
|
1000
|
-
* Available colorsets for theming.
|
|
1001
|
-
*
|
|
1002
|
-
* @returns {Object.<string, { w: string, b: string, cb: string, cg: string, cr: string, cy: string }>}
|
|
1003
|
-
* @public
|
|
1004
|
-
*/
|
|
1005
|
-
}, {
|
|
1006
|
-
key: "colorsets",
|
|
1007
|
-
value: function colorsets() {
|
|
1008
|
-
return _colorsets2["default"];
|
|
1009
|
-
}
|
|
1010
|
-
|
|
1011
|
-
/**
|
|
1012
|
-
* Available piecesets for theming.
|
|
1013
|
-
*
|
|
1014
|
-
* @returns {Object.<string, { bb: string, bk: string, bn: string, bp: string, bq: string, br: string, bx: string,
|
|
1015
|
-
* wb: string, wk: string, wn: string, wp: string, wq: string, wr: string, wx: string }>}
|
|
1016
|
-
* @public
|
|
1017
|
-
*/
|
|
1018
|
-
}, {
|
|
1019
|
-
key: "piecesets",
|
|
1020
|
-
value: function piecesets() {
|
|
1021
|
-
return _piecesets2["default"];
|
|
1022
|
-
}
|
|
1023
|
-
}]);
|
|
1024
|
-
return Chessboard;
|
|
1025
|
-
}(_react["default"].Component);
|
|
1026
|
-
exports["default"] = Chessboard;
|
|
1027
|
-
Chessboard.propTypes = {
|
|
1028
|
-
/**
|
|
1029
|
-
* Displayed position. Can be a [kokopu.Position](https://kokopu.yo35.org/docs/current/classes/Position.html) object,
|
|
1030
|
-
* a [FEN string](https://en.wikipedia.org/wiki/Forsyth%E2%80%93Edwards_Notation),
|
|
1031
|
-
* `'start'` (usual starting position), or `'empty'` (empty board).
|
|
1032
|
-
*
|
|
1033
|
-
* Optionally, the FEN string can be prefixed with `'variant:'`, `variant` corresponding to one of the
|
|
1034
|
-
* [game variant](https://kokopu.yo35.org/docs/current/types/GameVariant.html) supported by Kokopu. For instance:
|
|
1035
|
-
* `'chess960:nrkbqrbn/pppppppp/8/8/8/8/PPPPPPPP/NRKBQRBN w KQkq - 0 1'`.
|
|
1036
|
-
*/
|
|
1037
|
-
position: _propTypes["default"].oneOfType([_propTypes["default"].instanceOf(_kokopu.Position), _propTypes["default"].string]),
|
|
1038
|
-
/**
|
|
1039
|
-
* Displayed move (optional), defined either as a [kokopu.MoveDescriptor](https://kokopu.yo35.org/docs/current/classes/MoveDescriptor.html) object
|
|
1040
|
-
* or as a [SAN string](https://en.wikipedia.org/wiki/Algebraic_notation_(chess)) (e.g. `'Nf3'`). In both cases, it must represent
|
|
1041
|
-
* a legal move in position defined in attribute `position`.
|
|
1042
|
-
*/
|
|
1043
|
-
move: _propTypes["default"].oneOfType([_propTypes["default"].instanceOf(_kokopu.MoveDescriptor), _propTypes["default"].string]),
|
|
1044
|
-
/**
|
|
1045
|
-
* Square markers, defined as a "square -> color" struct (e.g. `{ e4: 'g', d5: 'r' }`) or as a comma-separated CSL string (e.g. `'Rd5,Ge4'`).
|
|
1046
|
-
*/
|
|
1047
|
-
squareMarkers: _propTypes["default"].oneOfType([_propTypes["default"].objectOf(_propTypes["default"].oneOf(['b', 'g', 'r', 'y'])), _propTypes["default"].string]),
|
|
1048
|
-
/**
|
|
1049
|
-
* Text markers, defined as a "square -> (symbol, color)" struct (e.g. `{ e4: { symbol: 'A', color: 'g' }, d5: { symbol: 'z', color: 'r' }}`)
|
|
1050
|
-
* or as a comma-separated CTL string (e.g. `'Rzd5,GAe4'`).
|
|
1051
|
-
*/
|
|
1052
|
-
textMarkers: _propTypes["default"].oneOfType([_propTypes["default"].objectOf(_propTypes["default"].shape({
|
|
1053
|
-
symbol: _propTypes["default"].string.isRequired,
|
|
1054
|
-
color: _propTypes["default"].oneOf(['b', 'g', 'r', 'y']).isRequired
|
|
1055
|
-
})), _propTypes["default"].string]),
|
|
1056
|
-
/**
|
|
1057
|
-
* Arrow markers, defined as a "squareFromSquareTo -> color" struct (e.g. `{ e2e4: 'g', g8f6: 'r', g8h6: 'y' }`)
|
|
1058
|
-
* or as a comma-separated CAL string (e.g. `'Ge2e4,Rg8f6,Yg8h6'`).
|
|
1059
|
-
*/
|
|
1060
|
-
arrowMarkers: _propTypes["default"].oneOfType([_propTypes["default"].objectOf(_propTypes["default"].oneOf(['b', 'g', 'r', 'y'])), _propTypes["default"].string]),
|
|
1061
|
-
/**
|
|
1062
|
-
* Whether the board is flipped (i.e. seen from Black's point of view) or not.
|
|
1063
|
-
*/
|
|
1064
|
-
flipped: _propTypes["default"].bool,
|
|
1065
|
-
/**
|
|
1066
|
-
* Size of the squares (in pixels). Must be an integer between `Chessboard.minSquareSize()` and `Chessboard.maxSquareSize()`.
|
|
1067
|
-
*/
|
|
1068
|
-
squareSize: _propTypes["default"].number,
|
|
1069
|
-
/**
|
|
1070
|
-
* Whether the row and column coordinates are visible or not.
|
|
1071
|
-
*/
|
|
1072
|
-
coordinateVisible: _propTypes["default"].bool,
|
|
1073
|
-
/**
|
|
1074
|
-
* Whether moves are highlighted with an arrow or not.
|
|
1075
|
-
*/
|
|
1076
|
-
moveArrowVisible: _propTypes["default"].bool,
|
|
1077
|
-
/**
|
|
1078
|
-
* Color of the move arrow.
|
|
1079
|
-
*/
|
|
1080
|
-
moveArrowColor: _propTypes["default"].oneOf(['b', 'g', 'r', 'y']),
|
|
1081
|
-
/**
|
|
1082
|
-
* Whether moves are animated or not.
|
|
1083
|
-
*/
|
|
1084
|
-
animated: _propTypes["default"].bool,
|
|
1085
|
-
/**
|
|
1086
|
-
* Color theme ID.
|
|
1087
|
-
*/
|
|
1088
|
-
colorset: _propTypes["default"].oneOf(Object.keys(_colorsets2["default"])),
|
|
1089
|
-
/**
|
|
1090
|
-
* Piece theme ID.
|
|
1091
|
-
*/
|
|
1092
|
-
pieceset: _propTypes["default"].oneOf(Object.keys(_piecesets2["default"])),
|
|
1093
|
-
/**
|
|
1094
|
-
* Limits applicable on small-screen devices. For instance, if set to
|
|
1095
|
-
* ```
|
|
1096
|
-
* [
|
|
1097
|
-
* { width: 768, squareSize: 40 },
|
|
1098
|
-
* { width: 375, squareSize: 24, coordinateVisible: false }
|
|
1099
|
-
* ]
|
|
1100
|
-
* ```
|
|
1101
|
-
* then on screens with resolution ≤768 pixels, the square size will be limited to 40 (whatever the value
|
|
1102
|
-
* of the `squareSize` attribute); in addition, on screens with resolution ≤375 pixels, the square size
|
|
1103
|
-
* will be limited to 24 and the row and column coordinates will always be hidden (whatever the value of the
|
|
1104
|
-
* `coordinateVisible` attribute).
|
|
1105
|
-
*/
|
|
1106
|
-
smallScreenLimits: _propTypes["default"].arrayOf(_propTypes["default"].shape({
|
|
1107
|
-
width: _propTypes["default"].number.isRequired,
|
|
1108
|
-
squareSize: _propTypes["default"].number,
|
|
1109
|
-
coordinateVisible: _propTypes["default"].bool
|
|
1110
|
-
})),
|
|
1111
|
-
/**
|
|
1112
|
-
* Type of action allowed with the mouse on the chessboard. If undefined, then the user cannot interact with the component.
|
|
1113
|
-
*
|
|
1114
|
-
* - `'movePieces'` allows the user to drag & drop the chess pieces from one square to another (regardless of the chess rules),
|
|
1115
|
-
* - `'clickSquares'` allows the user to click on squares,
|
|
1116
|
-
* - `'editArrows'` allows the user to draw arrow markers from one square to another (warning: attribute `editedArrowColor` must be set),
|
|
1117
|
-
* - `'playMoves'` allows the user to play legal chess moves (thus no interaction is possible if the displayed position is not legal).
|
|
1118
|
-
*/
|
|
1119
|
-
interactionMode: _propTypes["default"].oneOf(['movePieces', 'clickSquares', 'editArrows', 'playMoves']),
|
|
1120
|
-
/**
|
|
1121
|
-
* Color of the edited arrow (only used if `interactionMode` is set to `'editArrows'`).
|
|
1122
|
-
*/
|
|
1123
|
-
editedArrowColor: _propTypes["default"].oneOf(['b', 'g', 'r', 'y']),
|
|
1124
|
-
/**
|
|
1125
|
-
* Callback invoked when a piece is moved through drag&drop (only if `interactionMode` is set to `'movePieces'`).
|
|
1126
|
-
*
|
|
1127
|
-
* @param {string} from Origin square (e.g. `'g1'`).
|
|
1128
|
-
* @param {string} to Target square (e.g. `'f3'`).
|
|
1129
|
-
*/
|
|
1130
|
-
onPieceMoved: _propTypes["default"].func,
|
|
1131
|
-
/**
|
|
1132
|
-
* Callback invoked when the user clicks on a square (only if `interactionMode` is set to `'clickSquares'`).
|
|
1133
|
-
*
|
|
1134
|
-
* @param {string} square Clicked square (e.g. `e4`).
|
|
1135
|
-
*/
|
|
1136
|
-
onSquareClicked: _propTypes["default"].func,
|
|
1137
|
-
/**
|
|
1138
|
-
* Callback invoked when an arrow is dragged (only if `interactionMode` is set to `'editArrows'`).
|
|
1139
|
-
*
|
|
1140
|
-
* @param {string} from Origin square (e.g. `'g1'`).
|
|
1141
|
-
* @param {string} to Target square (e.g. `'f3'`).
|
|
1142
|
-
*/
|
|
1143
|
-
onArrowEdited: _propTypes["default"].func,
|
|
1144
|
-
/**
|
|
1145
|
-
* Callback invoked when a move is played (only if `interactionMode` is set to `'playMoves'`).
|
|
1146
|
-
*
|
|
1147
|
-
* @param {string} move SAN notation representing the played move (e.g. `Nxe5`).
|
|
1148
|
-
*/
|
|
1149
|
-
onMovePlayed: _propTypes["default"].func
|
|
1150
|
-
};
|
|
1151
|
-
Chessboard.defaultProps = {
|
|
1152
|
-
position: 'start',
|
|
1153
|
-
flipped: false,
|
|
1154
|
-
squareSize: 40,
|
|
1155
|
-
coordinateVisible: true,
|
|
1156
|
-
moveArrowVisible: true,
|
|
1157
|
-
moveArrowColor: 'b',
|
|
1158
|
-
animated: false,
|
|
1159
|
-
colorset: 'original',
|
|
1160
|
-
pieceset: 'cburnett'
|
|
1161
|
-
};
|
|
1162
|
-
|
|
1163
|
-
/**
|
|
1164
|
-
* Compute the limit applicable to the given window width.
|
|
1165
|
-
*/
|
|
1166
|
-
function computeSmallScreenLimits(key, smallScreenLimits, windowWidth) {
|
|
1167
|
-
if (!(smallScreenLimits instanceof Array)) {
|
|
1168
|
-
return undefined;
|
|
1169
|
-
}
|
|
1170
|
-
var applicableLimits = smallScreenLimits.filter(function (limit) {
|
|
1171
|
-
return limit && key in limit && windowWidth <= limit.width;
|
|
1172
|
-
}).sort(function (la, lb) {
|
|
1173
|
-
return la.width - lb.width;
|
|
1174
|
-
});
|
|
1175
|
-
return applicableLimits.length > 0 ? applicableLimits[0][key] : undefined;
|
|
1176
|
-
}
|
|
1177
|
-
|
|
1178
|
-
/**
|
|
1179
|
-
* Return the font size to use for coordinates assuming the given square size.
|
|
1180
|
-
*/
|
|
1181
|
-
function computeCoordinateFontSize(squareSize) {
|
|
1182
|
-
return squareSize <= 32 ? 8 : 8 + (squareSize - 32) * 0.2;
|
|
1183
|
-
}
|
|
1184
|
-
|
|
1185
|
-
/**
|
|
1186
|
-
* Try to interpret the given object as a chess position.
|
|
1187
|
-
*/
|
|
1188
|
-
function parsePosition(position) {
|
|
1189
|
-
if (position instanceof _kokopu.Position) {
|
|
1190
|
-
return {
|
|
1191
|
-
error: false,
|
|
1192
|
-
position: position
|
|
1193
|
-
};
|
|
1194
|
-
} else if (typeof position === 'string') {
|
|
1195
|
-
try {
|
|
1196
|
-
return {
|
|
1197
|
-
error: false,
|
|
1198
|
-
position: new _kokopu.Position(position)
|
|
1199
|
-
};
|
|
1200
|
-
} catch (e) {
|
|
1201
|
-
// istanbul ignore else
|
|
1202
|
-
if (e instanceof _kokopu.exception.InvalidFEN) {
|
|
1203
|
-
return {
|
|
1204
|
-
error: true,
|
|
1205
|
-
message: e.message
|
|
1206
|
-
};
|
|
1207
|
-
} else {
|
|
1208
|
-
throw e;
|
|
1209
|
-
}
|
|
1210
|
-
}
|
|
1211
|
-
} else {
|
|
1212
|
-
return {
|
|
1213
|
-
error: true,
|
|
1214
|
-
message: _i18n["default"].INVALID_POSITION_ATTRIBUTE_ERROR_MESSAGE
|
|
1215
|
-
};
|
|
1216
|
-
}
|
|
1217
|
-
}
|
|
1218
|
-
|
|
1219
|
-
/**
|
|
1220
|
-
* Try to interpret the given object `move` as a move descriptor based on the given position.
|
|
1221
|
-
*/
|
|
1222
|
-
function parseMove(position, move) {
|
|
1223
|
-
if (move instanceof _kokopu.MoveDescriptor) {
|
|
1224
|
-
return {
|
|
1225
|
-
error: false,
|
|
1226
|
-
move: move
|
|
1227
|
-
};
|
|
1228
|
-
} else if (typeof move === 'string') {
|
|
1229
|
-
try {
|
|
1230
|
-
return {
|
|
1231
|
-
error: false,
|
|
1232
|
-
move: position.notation(move)
|
|
1233
|
-
};
|
|
1234
|
-
} catch (e) {
|
|
1235
|
-
// istanbul ignore else
|
|
1236
|
-
if (e instanceof _kokopu.exception.InvalidNotation) {
|
|
1237
|
-
return {
|
|
1238
|
-
error: true,
|
|
1239
|
-
message: e.message
|
|
1240
|
-
};
|
|
1241
|
-
} else {
|
|
1242
|
-
throw e;
|
|
1243
|
-
}
|
|
1244
|
-
}
|
|
1245
|
-
} else {
|
|
1246
|
-
return {
|
|
1247
|
-
error: true,
|
|
1248
|
-
message: _i18n["default"].INVALID_MOVE_ATTRIBUTE_ERROR_MESSAGE
|
|
1249
|
-
};
|
|
1250
|
-
}
|
|
1251
|
-
}
|
|
1252
|
-
|
|
1253
|
-
/**
|
|
1254
|
-
* Try to interpret the given object as a list of markers.
|
|
1255
|
-
*/
|
|
1256
|
-
function parseMarkers(markers, parse, isValidKey, isValidValue) {
|
|
1257
|
-
if (typeof markers === 'string') {
|
|
1258
|
-
return parse(markers);
|
|
1259
|
-
} else if (_typeof(markers) === 'object') {
|
|
1260
|
-
var result = {};
|
|
1261
|
-
Object.entries(markers).filter(function (_ref7) {
|
|
1262
|
-
var _ref8 = _slicedToArray(_ref7, 2),
|
|
1263
|
-
key = _ref8[0],
|
|
1264
|
-
value = _ref8[1];
|
|
1265
|
-
return isValidKey(key) && isValidValue(value);
|
|
1266
|
-
}).forEach(function (_ref9) {
|
|
1267
|
-
var _ref10 = _slicedToArray(_ref9, 2),
|
|
1268
|
-
key = _ref10[0],
|
|
1269
|
-
value = _ref10[1];
|
|
1270
|
-
result[key] = value;
|
|
1271
|
-
});
|
|
1272
|
-
return result;
|
|
1273
|
-
} else {
|
|
1274
|
-
return {};
|
|
1275
|
-
}
|
|
1276
|
-
}
|