@zoendev/react-chessboard
Version:
The React Chessboard Library used at ChessOpenings.co.uk. Inspired and adapted from the unmaintained Chessboard.jsx.
939 lines (907 loc) • 240 kB
JavaScript
'use strict';
var jsxRuntime = require('react/jsx-runtime');
var react = require('react');
/******************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
function __rest(s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
}
const COLUMNS = "abcdefgh".split("");
const START_POSITION_OBJECT = {
a8: "bR",
b8: "bN",
c8: "bB",
d8: "bQ",
e8: "bK",
f8: "bB",
g8: "bN",
h8: "bR",
a7: "bP",
b7: "bP",
c7: "bP",
d7: "bP",
e7: "bP",
f7: "bP",
g7: "bP",
h7: "bP",
a2: "wP",
b2: "wP",
c2: "wP",
d2: "wP",
e2: "wP",
f2: "wP",
g2: "wP",
h2: "wP",
a1: "wR",
b1: "wN",
c1: "wB",
d1: "wQ",
e1: "wK",
f1: "wB",
g1: "wN",
h1: "wR",
};
const WHITE_COLUMN_VALUES = {
a: 0,
b: 1,
c: 2,
d: 3,
e: 4,
f: 5,
g: 6,
h: 7,
};
const BLACK_COLUMN_VALUES = {
a: 7,
b: 6,
c: 5,
d: 4,
e: 3,
f: 2,
g: 1,
h: 0,
};
const WHITE_ROWS = [7, 6, 5, 4, 3, 2, 1, 0];
const BLACK_ROWS = [0, 1, 2, 3, 4, 5, 6, 7];
// https://commons.wikimedia.org/wiki/Category:SVG_chess_pieces
// By en:User:Cburnett - Own work
// This W3C - unspecified vector image was created with Inkscape., CC BY - SA 3.0, https://commons.wikimedia.org/w/index.php?curid=1499810
const defaultPieces = {
wP: (jsxRuntime.jsx("svg", Object.assign({ xmlns: "http://www.w3.org/2000/svg", version: "1.1", width: "45", height: "45" }, { children: jsxRuntime.jsx("path", { d: "m 22.5,9 c -2.21,0 -4,1.79 -4,4 0,0.89 0.29,1.71 0.78,2.38 C 17.33,16.5 16,18.59 16,21 c 0,2.03 0.94,3.84 2.41,5.03 C 15.41,27.09 11,31.58 11,39.5 H 34 C 34,31.58 29.59,27.09 26.59,26.03 28.06,24.84 29,23.03 29,21 29,18.59 27.67,16.5 25.72,15.38 26.21,14.71 26.5,13.89 26.5,13 c 0,-2.21 -1.79,-4 -4,-4 z", style: {
opacity: "1",
fill: "#ffffff",
fillOpacity: "1",
fillRule: "nonzero",
stroke: "#000000",
strokeWidth: "1.5",
strokeLinecap: "round",
strokeLinejoin: "miter",
strokeMiterlimit: "4",
strokeDasharray: "none",
strokeOpacity: "1",
} }) }))),
wR: (jsxRuntime.jsx("svg", Object.assign({ xmlns: "http://www.w3.org/2000/svg", version: "1.1", width: "45", height: "45" }, { children: jsxRuntime.jsxs("g", Object.assign({ style: {
opacity: "1",
fill: "#ffffff",
fillOpacity: "1",
fillRule: "evenodd",
stroke: "#000000",
strokeWidth: "1.5",
strokeLinecap: "round",
strokeLinejoin: "round",
strokeMiterlimit: "4",
strokeDasharray: "none",
strokeOpacity: "1",
} }, { children: [jsxRuntime.jsx("path", { d: "M 9,39 L 36,39 L 36,36 L 9,36 L 9,39 z ", style: { strokeLinecap: "butt" } }), jsxRuntime.jsx("path", { d: "M 12,36 L 12,32 L 33,32 L 33,36 L 12,36 z ", style: { strokeLinecap: "butt" } }), jsxRuntime.jsx("path", { d: "M 11,14 L 11,9 L 15,9 L 15,11 L 20,11 L 20,9 L 25,9 L 25,11 L 30,11 L 30,9 L 34,9 L 34,14", style: { strokeLinecap: "butt" } }), jsxRuntime.jsx("path", { d: "M 34,14 L 31,17 L 14,17 L 11,14" }), jsxRuntime.jsx("path", { d: "M 31,17 L 31,29.5 L 14,29.5 L 14,17", style: { strokeLinecap: "butt", strokeLinejoin: "miter" } }), jsxRuntime.jsx("path", { d: "M 31,29.5 L 32.5,32 L 12.5,32 L 14,29.5" }), jsxRuntime.jsx("path", { d: "M 11,14 L 34,14", style: { fill: "none", stroke: "#000000", strokeLinejoin: "miter" } })] })) }))),
wN: (jsxRuntime.jsx("svg", Object.assign({ xmlns: "http://www.w3.org/2000/svg", version: "1.1", width: "45", height: "45" }, { children: jsxRuntime.jsxs("g", Object.assign({ style: {
opacity: "1",
fill: "none",
fillOpacity: "1",
fillRule: "evenodd",
stroke: "#000000",
strokeWidth: "1.5",
strokeLinecap: "round",
strokeLinejoin: "round",
strokeMiterlimit: "4",
strokeDasharray: "none",
strokeOpacity: "1",
} }, { children: [jsxRuntime.jsx("path", { d: "M 22,10 C 32.5,11 38.5,18 38,39 L 15,39 C 15,30 25,32.5 23,18", style: { fill: "#ffffff", stroke: "#000000" } }), jsxRuntime.jsx("path", { d: "M 24,18 C 24.38,20.91 18.45,25.37 16,27 C 13,29 13.18,31.34 11,31 C 9.958,30.06 12.41,27.96 11,28 C 10,28 11.19,29.23 10,30 C 9,30 5.997,31 6,26 C 6,24 12,14 12,14 C 12,14 13.89,12.1 14,10.5 C 13.27,9.506 13.5,8.5 13.5,7.5 C 14.5,6.5 16.5,10 16.5,10 L 18.5,10 C 18.5,10 19.28,8.008 21,7 C 22,7 22,10 22,10", style: { fill: "#ffffff", stroke: "#000000" } }), jsxRuntime.jsx("path", { d: "M 9.5 25.5 A 0.5 0.5 0 1 1 8.5,25.5 A 0.5 0.5 0 1 1 9.5 25.5 z", style: { fill: "#000000", stroke: "#000000" } }), jsxRuntime.jsx("path", { d: "M 15 15.5 A 0.5 1.5 0 1 1 14,15.5 A 0.5 1.5 0 1 1 15 15.5 z", transform: "matrix(0.866,0.5,-0.5,0.866,9.693,-5.173)", style: { fill: "#000000", stroke: "#000000" } })] })) }))),
wB: (jsxRuntime.jsx("svg", Object.assign({ xmlns: "http://www.w3.org/2000/svg", version: "1.1", width: "45", height: "45" }, { children: jsxRuntime.jsxs("g", Object.assign({ style: {
opacity: "1",
fill: "none",
fillRule: "evenodd",
fillOpacity: "1",
stroke: "#000000",
strokeWidth: "1.5",
strokeLinecap: "round",
strokeLinejoin: "round",
strokeMiterlimit: "4",
strokeDasharray: "none",
strokeOpacity: "1",
} }, { children: [jsxRuntime.jsxs("g", Object.assign({ style: { fill: "#ffffff", stroke: "#000000", strokeLinecap: "butt" } }, { children: [jsxRuntime.jsx("path", { d: "M 9,36 C 12.39,35.03 19.11,36.43 22.5,34 C 25.89,36.43 32.61,35.03 36,36 C 36,36 37.65,36.54 39,38 C 38.32,38.97 37.35,38.99 36,38.5 C 32.61,37.53 25.89,38.96 22.5,37.5 C 19.11,38.96 12.39,37.53 9,38.5 C 7.65,38.99 6.68,38.97 6,38 C 7.35,36.54 9,36 9,36 z" }), jsxRuntime.jsx("path", { d: "M 15,32 C 17.5,34.5 27.5,34.5 30,32 C 30.5,30.5 30,30 30,30 C 30,27.5 27.5,26 27.5,26 C 33,24.5 33.5,14.5 22.5,10.5 C 11.5,14.5 12,24.5 17.5,26 C 17.5,26 15,27.5 15,30 C 15,30 14.5,30.5 15,32 z" }), jsxRuntime.jsx("path", { d: "M 25 8 A 2.5 2.5 0 1 1 20,8 A 2.5 2.5 0 1 1 25 8 z" })] })), jsxRuntime.jsx("path", { d: "M 17.5,26 L 27.5,26 M 15,30 L 30,30 M 22.5,15.5 L 22.5,20.5 M 20,18 L 25,18", style: { fill: "none", stroke: "#000000", strokeLinejoin: "miter" } })] })) }))),
wQ: (jsxRuntime.jsx("svg", Object.assign({ xmlns: "http://www.w3.org/2000/svg", version: "1.1", width: "45", height: "45" }, { children: jsxRuntime.jsxs("g", Object.assign({ style: {
fill: "#ffffff",
stroke: "#000000",
strokeWidth: "1.5",
strokeLinejoin: "round",
} }, { children: [jsxRuntime.jsx("path", { d: "M 9,26 C 17.5,24.5 30,24.5 36,26 L 38.5,13.5 L 31,25 L 30.7,10.9 L 25.5,24.5 L 22.5,10 L 19.5,24.5 L 14.3,10.9 L 14,25 L 6.5,13.5 L 9,26 z" }), jsxRuntime.jsx("path", { d: "M 9,26 C 9,28 10.5,28 11.5,30 C 12.5,31.5 12.5,31 12,33.5 C 10.5,34.5 11,36 11,36 C 9.5,37.5 11,38.5 11,38.5 C 17.5,39.5 27.5,39.5 34,38.5 C 34,38.5 35.5,37.5 34,36 C 34,36 34.5,34.5 33,33.5 C 32.5,31 32.5,31.5 33.5,30 C 34.5,28 36,28 36,26 C 27.5,24.5 17.5,24.5 9,26 z" }), jsxRuntime.jsx("path", { d: "M 11.5,30 C 15,29 30,29 33.5,30", style: { fill: "none" } }), jsxRuntime.jsx("path", { d: "M 12,33.5 C 18,32.5 27,32.5 33,33.5", style: { fill: "none" } }), jsxRuntime.jsx("circle", { cx: "6", cy: "12", r: "2" }), jsxRuntime.jsx("circle", { cx: "14", cy: "9", r: "2" }), jsxRuntime.jsx("circle", { cx: "22.5", cy: "8", r: "2" }), jsxRuntime.jsx("circle", { cx: "31", cy: "9", r: "2" }), jsxRuntime.jsx("circle", { cx: "39", cy: "12", r: "2" })] })) }))),
wK: (jsxRuntime.jsx("svg", Object.assign({ xmlns: "http://www.w3.org/2000/svg", version: "1.1", width: "45", height: "45" }, { children: jsxRuntime.jsxs("g", Object.assign({ style: {
fill: "none",
fillOpacity: "1",
fillRule: "evenodd",
stroke: "#000000",
strokeWidth: "1.5",
strokeLinecap: "round",
strokeLinejoin: "round",
strokeMiterlimit: "4",
strokeDasharray: "none",
strokeOpacity: "1",
} }, { children: [jsxRuntime.jsx("path", { d: "M 22.5,11.63 L 22.5,6", style: { fill: "none", stroke: "#000000", strokeLinejoin: "miter" } }), jsxRuntime.jsx("path", { d: "M 20,8 L 25,8", style: { fill: "none", stroke: "#000000", strokeLinejoin: "miter" } }), jsxRuntime.jsx("path", { d: "M 22.5,25 C 22.5,25 27,17.5 25.5,14.5 C 25.5,14.5 24.5,12 22.5,12 C 20.5,12 19.5,14.5 19.5,14.5 C 18,17.5 22.5,25 22.5,25", style: {
fill: "#ffffff",
stroke: "#000000",
strokeLinecap: "butt",
strokeLinejoin: "miter",
} }), jsxRuntime.jsx("path", { d: "M 12.5,37 C 18,40.5 27,40.5 32.5,37 L 32.5,30 C 32.5,30 41.5,25.5 38.5,19.5 C 34.5,13 25,16 22.5,23.5 L 22.5,27 L 22.5,23.5 C 20,16 10.5,13 6.5,19.5 C 3.5,25.5 12.5,30 12.5,30 L 12.5,37", style: { fill: "#ffffff", stroke: "#000000" } }), jsxRuntime.jsx("path", { d: "M 12.5,30 C 18,27 27,27 32.5,30", style: { fill: "none", stroke: "#000000" } }), jsxRuntime.jsx("path", { d: "M 12.5,33.5 C 18,30.5 27,30.5 32.5,33.5", style: { fill: "none", stroke: "#000000" } }), jsxRuntime.jsx("path", { d: "M 12.5,37 C 18,34 27,34 32.5,37", style: { fill: "none", stroke: "#000000" } })] })) }))),
bP: (jsxRuntime.jsx("svg", Object.assign({ xmlns: "http://www.w3.org/2000/svg", version: "1.1", width: "45", height: "45" }, { children: jsxRuntime.jsx("path", { d: "m 22.5,9 c -2.21,0 -4,1.79 -4,4 0,0.89 0.29,1.71 0.78,2.38 C 17.33,16.5 16,18.59 16,21 c 0,2.03 0.94,3.84 2.41,5.03 C 15.41,27.09 11,31.58 11,39.5 H 34 C 34,31.58 29.59,27.09 26.59,26.03 28.06,24.84 29,23.03 29,21 29,18.59 27.67,16.5 25.72,15.38 26.21,14.71 26.5,13.89 26.5,13 c 0,-2.21 -1.79,-4 -4,-4 z", style: {
opacity: "1",
fill: "#000000",
fillOpacity: "1",
fillRule: "nonzero",
stroke: "#000000",
strokeWidth: "1.5",
strokeLinecap: "round",
strokeLinejoin: "miter",
strokeMiterlimit: "4",
strokeDasharray: "none",
strokeOpacity: "1",
} }) }))),
bR: (jsxRuntime.jsx("svg", Object.assign({ xmlns: "http://www.w3.org/2000/svg", version: "1.1", width: "45", height: "45" }, { children: jsxRuntime.jsxs("g", Object.assign({ style: {
opacity: "1",
fill: "#000000",
fillOpacity: "1",
fillRule: "evenodd",
stroke: "#000000",
strokeWidth: "1.5",
strokeLinecap: "round",
strokeLinejoin: "round",
strokeMiterlimit: "4",
strokeDasharray: "none",
strokeOpacity: "1",
} }, { children: [jsxRuntime.jsx("path", { d: "M 9,39 L 36,39 L 36,36 L 9,36 L 9,39 z ", style: { strokeLinecap: "butt" } }), jsxRuntime.jsx("path", { d: "M 12.5,32 L 14,29.5 L 31,29.5 L 32.5,32 L 12.5,32 z ", style: { strokeLinecap: "butt" } }), jsxRuntime.jsx("path", { d: "M 12,36 L 12,32 L 33,32 L 33,36 L 12,36 z ", style: { strokeLinecap: "butt" } }), jsxRuntime.jsx("path", { d: "M 14,29.5 L 14,16.5 L 31,16.5 L 31,29.5 L 14,29.5 z ", style: { strokeLinecap: "butt", strokeLinejoin: "miter" } }), jsxRuntime.jsx("path", { d: "M 14,16.5 L 11,14 L 34,14 L 31,16.5 L 14,16.5 z ", style: { strokeLinecap: "butt" } }), jsxRuntime.jsx("path", { d: "M 11,14 L 11,9 L 15,9 L 15,11 L 20,11 L 20,9 L 25,9 L 25,11 L 30,11 L 30,9 L 34,9 L 34,14 L 11,14 z ", style: { strokeLinecap: "butt" } }), jsxRuntime.jsx("path", { d: "M 12,35.5 L 33,35.5 L 33,35.5", style: {
fill: "none",
stroke: "#ffffff",
strokeWidth: "1",
strokeLinejoin: "miter",
} }), jsxRuntime.jsx("path", { d: "M 13,31.5 L 32,31.5", style: {
fill: "none",
stroke: "#ffffff",
strokeWidth: "1",
strokeLinejoin: "miter",
} }), jsxRuntime.jsx("path", { d: "M 14,29.5 L 31,29.5", style: {
fill: "none",
stroke: "#ffffff",
strokeWidth: "1",
strokeLinejoin: "miter",
} }), jsxRuntime.jsx("path", { d: "M 14,16.5 L 31,16.5", style: {
fill: "none",
stroke: "#ffffff",
strokeWidth: "1",
strokeLinejoin: "miter",
} }), jsxRuntime.jsx("path", { d: "M 11,14 L 34,14", style: {
fill: "none",
stroke: "#ffffff",
strokeWidth: "1",
strokeLinejoin: "miter",
} })] })) }))),
bN: (jsxRuntime.jsx("svg", Object.assign({ xmlns: "http://www.w3.org/2000/svg", version: "1.1", width: "45", height: "45" }, { children: jsxRuntime.jsxs("g", Object.assign({ style: {
opacity: "1",
fill: "none",
fillOpacity: "1",
fillRule: "evenodd",
stroke: "#000000",
strokeWidth: "1.5",
strokeLinecap: "round",
strokeLinejoin: "round",
strokeMiterlimit: "4",
strokeDasharray: "none",
strokeOpacity: "1",
} }, { children: [jsxRuntime.jsx("path", { d: "M 22,10 C 32.5,11 38.5,18 38,39 L 15,39 C 15,30 25,32.5 23,18", style: { fill: "#000000", stroke: "#000000" } }), jsxRuntime.jsx("path", { d: "M 24,18 C 24.38,20.91 18.45,25.37 16,27 C 13,29 13.18,31.34 11,31 C 9.958,30.06 12.41,27.96 11,28 C 10,28 11.19,29.23 10,30 C 9,30 5.997,31 6,26 C 6,24 12,14 12,14 C 12,14 13.89,12.1 14,10.5 C 13.27,9.506 13.5,8.5 13.5,7.5 C 14.5,6.5 16.5,10 16.5,10 L 18.5,10 C 18.5,10 19.28,8.008 21,7 C 22,7 22,10 22,10", style: { fill: "#000000", stroke: "#000000" } }), jsxRuntime.jsx("path", { d: "M 9.5 25.5 A 0.5 0.5 0 1 1 8.5,25.5 A 0.5 0.5 0 1 1 9.5 25.5 z", style: { fill: "#ffffff", stroke: "#ffffff" } }), jsxRuntime.jsx("path", { d: "M 15 15.5 A 0.5 1.5 0 1 1 14,15.5 A 0.5 1.5 0 1 1 15 15.5 z", transform: "matrix(0.866,0.5,-0.5,0.866,9.693,-5.173)", style: { fill: "#ffffff", stroke: "#ffffff" } }), jsxRuntime.jsx("path", { d: "M 24.55,10.4 L 24.1,11.85 L 24.6,12 C 27.75,13 30.25,14.49 32.5,18.75 C 34.75,23.01 35.75,29.06 35.25,39 L 35.2,39.5 L 37.45,39.5 L 37.5,39 C 38,28.94 36.62,22.15 34.25,17.66 C 31.88,13.17 28.46,11.02 25.06,10.5 L 24.55,10.4 z ", style: { fill: "#ffffff", stroke: "none" } })] })) }))),
bB: (jsxRuntime.jsx("svg", Object.assign({ xmlns: "http://www.w3.org/2000/svg", version: "1.1", width: "45", height: "45" }, { children: jsxRuntime.jsxs("g", Object.assign({ style: {
opacity: "1",
fill: "none",
fillRule: "evenodd",
fillOpacity: "1",
stroke: "#000000",
strokeWidth: "1.5",
strokeLinecap: "round",
strokeLinejoin: "round",
strokeMiterlimit: "4",
strokeDasharray: "none",
strokeOpacity: "1",
} }, { children: [jsxRuntime.jsxs("g", Object.assign({ style: { fill: "#000000", stroke: "#000000", strokeLinecap: "butt" } }, { children: [jsxRuntime.jsx("path", { d: "M 9,36 C 12.39,35.03 19.11,36.43 22.5,34 C 25.89,36.43 32.61,35.03 36,36 C 36,36 37.65,36.54 39,38 C 38.32,38.97 37.35,38.99 36,38.5 C 32.61,37.53 25.89,38.96 22.5,37.5 C 19.11,38.96 12.39,37.53 9,38.5 C 7.65,38.99 6.68,38.97 6,38 C 7.35,36.54 9,36 9,36 z" }), jsxRuntime.jsx("path", { d: "M 15,32 C 17.5,34.5 27.5,34.5 30,32 C 30.5,30.5 30,30 30,30 C 30,27.5 27.5,26 27.5,26 C 33,24.5 33.5,14.5 22.5,10.5 C 11.5,14.5 12,24.5 17.5,26 C 17.5,26 15,27.5 15,30 C 15,30 14.5,30.5 15,32 z" }), jsxRuntime.jsx("path", { d: "M 25 8 A 2.5 2.5 0 1 1 20,8 A 2.5 2.5 0 1 1 25 8 z" })] })), jsxRuntime.jsx("path", { d: "M 17.5,26 L 27.5,26 M 15,30 L 30,30 M 22.5,15.5 L 22.5,20.5 M 20,18 L 25,18", style: { fill: "none", stroke: "#ffffff", strokeLinejoin: "miter" } })] })) }))),
bQ: (jsxRuntime.jsx("svg", Object.assign({ xmlns: "http://www.w3.org/2000/svg", version: "1.1", width: "45", height: "45" }, { children: jsxRuntime.jsxs("g", Object.assign({ style: {
fill: "#000000",
stroke: "#000000",
strokeWidth: "1.5",
strokeLinecap: "round",
strokeLinejoin: "round",
} }, { children: [jsxRuntime.jsx("path", { d: "M 9,26 C 17.5,24.5 30,24.5 36,26 L 38.5,13.5 L 31,25 L 30.7,10.9 L 25.5,24.5 L 22.5,10 L 19.5,24.5 L 14.3,10.9 L 14,25 L 6.5,13.5 L 9,26 z", style: { strokeLinecap: "butt", fill: "#000000" } }), jsxRuntime.jsx("path", { d: "m 9,26 c 0,2 1.5,2 2.5,4 1,1.5 1,1 0.5,3.5 -1.5,1 -1,2.5 -1,2.5 -1.5,1.5 0,2.5 0,2.5 6.5,1 16.5,1 23,0 0,0 1.5,-1 0,-2.5 0,0 0.5,-1.5 -1,-2.5 -0.5,-2.5 -0.5,-2 0.5,-3.5 1,-2 2.5,-2 2.5,-4 -8.5,-1.5 -18.5,-1.5 -27,0 z" }), jsxRuntime.jsx("path", { d: "M 11.5,30 C 15,29 30,29 33.5,30" }), jsxRuntime.jsx("path", { d: "m 12,33.5 c 6,-1 15,-1 21,0" }), jsxRuntime.jsx("circle", { cx: "6", cy: "12", r: "2" }), jsxRuntime.jsx("circle", { cx: "14", cy: "9", r: "2" }), jsxRuntime.jsx("circle", { cx: "22.5", cy: "8", r: "2" }), jsxRuntime.jsx("circle", { cx: "31", cy: "9", r: "2" }), jsxRuntime.jsx("circle", { cx: "39", cy: "12", r: "2" }), jsxRuntime.jsx("path", { d: "M 11,38.5 A 35,35 1 0 0 34,38.5", style: { fill: "none", stroke: "#000000", strokeLinecap: "butt" } }), jsxRuntime.jsxs("g", Object.assign({ style: { fill: "none", stroke: "#ffffff" } }, { children: [jsxRuntime.jsx("path", { d: "M 11,29 A 35,35 1 0 1 34,29" }), jsxRuntime.jsx("path", { d: "M 12.5,31.5 L 32.5,31.5" }), jsxRuntime.jsx("path", { d: "M 11.5,34.5 A 35,35 1 0 0 33.5,34.5" }), jsxRuntime.jsx("path", { d: "M 10.5,37.5 A 35,35 1 0 0 34.5,37.5" })] }))] })) }))),
bK: (jsxRuntime.jsx("svg", Object.assign({ xmlns: "http://www.w3.org/2000/svg", version: "1.1", width: "45", height: "45" }, { children: jsxRuntime.jsxs("g", Object.assign({ style: {
fill: "none",
fillOpacity: "1",
fillRule: "evenodd",
stroke: "#000000",
strokeWidth: "1.5",
strokeLinecap: "round",
strokeLinejoin: "round",
strokeMiterlimit: "4",
strokeDasharray: "none",
strokeOpacity: "1",
} }, { children: [jsxRuntime.jsx("path", { d: "M 22.5,11.63 L 22.5,6", style: { fill: "none", stroke: "#000000", strokeLinejoin: "miter" }, id: "path6570" }), jsxRuntime.jsx("path", { d: "M 22.5,25 C 22.5,25 27,17.5 25.5,14.5 C 25.5,14.5 24.5,12 22.5,12 C 20.5,12 19.5,14.5 19.5,14.5 C 18,17.5 22.5,25 22.5,25", style: {
fill: "#000000",
fillOpacity: "1",
strokeLinecap: "butt",
strokeLinejoin: "miter",
} }), jsxRuntime.jsx("path", { d: "M 12.5,37 C 18,40.5 27,40.5 32.5,37 L 32.5,30 C 32.5,30 41.5,25.5 38.5,19.5 C 34.5,13 25,16 22.5,23.5 L 22.5,27 L 22.5,23.5 C 20,16 10.5,13 6.5,19.5 C 3.5,25.5 12.5,30 12.5,30 L 12.5,37", style: { fill: "#000000", stroke: "#000000" } }), jsxRuntime.jsx("path", { d: "M 20,8 L 25,8", style: { fill: "none", stroke: "#000000", strokeLinejoin: "miter" } }), jsxRuntime.jsx("path", { d: "M 32,29.5 C 32,29.5 40.5,25.5 38.03,19.85 C 34.15,14 25,18 22.5,24.5 L 22.5,26.6 L 22.5,24.5 C 20,18 10.85,14 6.97,19.85 C 4.5,25.5 13,29.5 13,29.5", style: { fill: "none", stroke: "#ffffff" } }), jsxRuntime.jsx("path", { d: "M 12.5,30 C 18,27 27,27 32.5,30 M 12.5,33.5 C 18,30.5 27,30.5 32.5,33.5 M 12.5,37 C 18,34 27,34 32.5,37", style: { fill: "none", stroke: "#ffffff" } })] })) }))),
};
/**
* Retrieves the coordinates at the centre of the requested square, relative to the top left of the board (0, 0).
*/
function getRelativeCoords(boardOrientation, boardWidth, square) {
const squareWidth = boardWidth / 8;
const columns = boardOrientation === "white" ? WHITE_COLUMN_VALUES : BLACK_COLUMN_VALUES;
const rows = boardOrientation === "white" ? WHITE_ROWS : BLACK_ROWS;
const x = columns[square[0]] * squareWidth + squareWidth / 2;
const y = rows[parseInt(square[1], 10) - 1] * squareWidth + squareWidth / 2;
return { x, y };
}
/**
* Returns whether the passed position is different from the start position.
*/
function isDifferentFromStart(newPosition) {
let isDifferent = false;
Object.keys(START_POSITION_OBJECT).forEach((square) => {
if (newPosition[square] !== START_POSITION_OBJECT[square])
isDifferent = true;
});
Object.keys(newPosition).forEach((square) => {
if (START_POSITION_OBJECT[square] !== newPosition[square])
isDifferent = true;
});
return isDifferent;
}
/**
* Returns what pieces have been added and what pieces have been removed between board positions.
*/
function getPositionDifferences(currentPosition, newPosition) {
const difference = {
removed: {},
added: {},
};
// removed from current
Object.keys(currentPosition).forEach((square) => {
if (newPosition[square] !== currentPosition[square])
difference.removed[square] = currentPosition[square];
});
// added from new
Object.keys(newPosition).forEach((square) => {
if (currentPosition[square] !== newPosition[square])
difference.added[square] = newPosition[square];
});
return difference;
}
/**
* Converts a fen string or existing position object to a position object.
*/
function convertPositionToObject(position) {
if (position === "start") {
return START_POSITION_OBJECT;
}
if (typeof position === "string") {
// attempt to convert fen to position object
return fenToObj(position);
}
return position;
}
/**
* Converts a fen string to a position object.
*/
function fenToObj(fen) {
if (!isValidFen(fen))
return {};
// cut off any move, castling, etc info from the end. we're only interested in position information
fen = fen.replace(/ .+$/, "");
const rows = fen.split("/");
const position = {};
let currentRow = 8;
for (let i = 0; i < 8; i++) {
const row = rows[i].split("");
let colIdx = 0;
// loop through each character in the FEN section
for (let j = 0; j < row.length; j++) {
// number / empty squares
if (row[j].search(/[1-8]/) !== -1) {
const numEmptySquares = parseInt(row[j], 10);
colIdx = colIdx + numEmptySquares;
}
else {
// piece
const square = COLUMNS[colIdx] + currentRow;
position[square] = fenToPieceCode(row[j]);
colIdx = colIdx + 1;
}
}
currentRow = currentRow - 1;
}
return position;
}
/**
* Returns whether string is valid fen notation.
*/
function isValidFen(fen) {
// cut off any move, castling, etc info from the end. we're only interested in position information
fen = fen.replace(/ .+$/, "");
// expand the empty square numbers to just 1s
fen = expandFenEmptySquares(fen);
// fen should be 8 sections separated by slashes
const chunks = fen.split("/");
if (chunks.length !== 8)
return false;
// check each section
for (let i = 0; i < 8; i++) {
if (chunks[i].length !== 8 || chunks[i].search(/[^kqrnbpKQRNBP1]/) !== -1) {
return false;
}
}
return true;
}
/**
* Expand out fen notation to countable characters for validation
*/
function expandFenEmptySquares(fen) {
return fen
.replace(/8/g, "11111111")
.replace(/7/g, "1111111")
.replace(/6/g, "111111")
.replace(/5/g, "11111")
.replace(/4/g, "1111")
.replace(/3/g, "111")
.replace(/2/g, "11");
}
/**
* Convert fen piece code to camel case notation. e.g. bP, wK.
*/
function fenToPieceCode(piece) {
// black piece
if (piece.toLowerCase() === piece) {
return ("b" + piece.toUpperCase());
}
// white piece
return ("w" + piece.toUpperCase());
}
const useArrows = (customArrows, areArrowsAllowed = true, onArrowsChange, customArrowColor) => {
// arrows passed programatically to `ChessBoard` as a react prop
const [customArrowsSet, setCustomArrows] = react.useState([]);
// arrows drawn with mouse by user on the board
const [arrows, setArrows] = react.useState([]);
// active arrow which user draws while dragging mouse
const [newArrow, setNewArrow] = react.useState();
// handle external `customArrows` props changes
react.useEffect(() => {
if (Array.isArray(customArrows)) {
// so that custom arrows overwrite temporary arrows
clearArrows();
setCustomArrows(
//filter out arrows which starts and ends in the same square
customArrows === null || customArrows === void 0 ? void 0 : customArrows.filter((arrow) => arrow[0] !== arrow[1]));
}
}, [customArrows]);
// callback when arrows changed after user interaction
react.useEffect(() => {
onArrowsChange === null || onArrowsChange === void 0 ? void 0 : onArrowsChange(arrows);
}, [arrows]);
// function clears all arrows drawed by user
function clearArrows() {
setArrows([]);
setNewArrow(undefined);
}
const drawNewArrow = (fromSquare, toSquare) => {
if (!areArrowsAllowed)
return;
setNewArrow([fromSquare, toSquare, customArrowColor]);
};
const allBoardArrows = [...arrows, ...customArrowsSet];
const onArrowDrawEnd = (fromSquare, toSquare) => {
if (fromSquare === toSquare || !areArrowsAllowed)
return;
let arrowsCopy;
const newArrow = [fromSquare, toSquare, customArrowColor];
const isNewArrowUnique = allBoardArrows.every(([arrowFrom, arrowTo]) => {
return !(arrowFrom === fromSquare && arrowTo === toSquare);
});
// add the newArrow to arrows array if it is unique
if (isNewArrowUnique) {
arrowsCopy = [...arrows, newArrow];
}
// remove it from the board if we already have same arrow in arrows array
else {
arrowsCopy = arrows.filter(([arrowFrom, arrowTo]) => {
return !(arrowFrom === fromSquare && arrowTo === toSquare);
});
}
setNewArrow(undefined);
setArrows(arrowsCopy);
};
return {
arrows: allBoardArrows,
newArrow,
clearArrows,
drawNewArrow,
setArrows,
onArrowDrawEnd,
};
};
const ChessboardContext = react.createContext({});
const useChessboard = () => react.useContext(ChessboardContext);
const ChessboardProvider = react.forwardRef(({ allowDragOutsideBoard = true, animationDuration = 300, areArrowsAllowed = true, arePiecesDraggable = true, arePremovesAllowed = false, autoPromoteToQueen = false, boardOrientation = "white", boardWidth, children, clearPremovesOnRightClick = true, customArrows, customArrowColor = "rgb(255,170,0)", customBoardStyle, customNotationStyle, customDarkSquareStyle = { backgroundColor: "#B58863" }, customDropSquareStyle = {
boxShadow: "inset 0 0 1px 6px rgba(255,255,255,0.75)",
}, customLightSquareStyle = { backgroundColor: "#F0D9B5" }, customPieces, customPremoveDarkSquareStyle = { backgroundColor: "#A42323" }, customPremoveLightSquareStyle = { backgroundColor: "#BD2828" }, customSquare = "div", customSquareStyles, dropOffBoardAction = "snapback", id = 0, isDraggablePiece = () => true, getPositionObject = () => { }, onArrowsChange = () => { }, onDragOverSquare = () => { }, onMouseOutSquare = () => { }, onMouseOverSquare = () => { }, onPieceClick = () => { }, onPieceDragBegin = () => { }, onPieceDragEnd = () => { }, onPieceDrop = () => true, onPieceDropOffBoard = () => { }, onPromotionCheck = (sourceSquare, targetSquare, piece) => {
return (((piece === "wP" &&
sourceSquare[1] === "7" &&
targetSquare[1] === "8") ||
(piece === "bP" &&
sourceSquare[1] === "2" &&
targetSquare[1] === "1")) &&
Math.abs(sourceSquare.charCodeAt(0) - targetSquare.charCodeAt(0)) <= 1);
}, onPromotionPieceSelect = () => true, onSparePieceDrop = () => true, onSquareClick = () => { }, onSquareRightClick = () => { }, position = "start", promotionDialogVariant = "default", promotionToSquare = null, showBoardNotation = true, showPromotionDialog = false, snapToCursor = true, }, ref) => {
// position stored and displayed on board
const [currentPosition, setCurrentPosition] = react.useState(convertPositionToObject(position));
// calculated differences between current and incoming positions
const [positionDifferences, setPositionDifferences] = react.useState({ removed: {}, added: {} });
// colour of last piece moved to determine if premoving
const [lastPieceColour, setLastPieceColour] = react.useState(undefined);
// show / hide promotion dialog
const [showPromoteDialog, setShowPromoteDialog] = react.useState(showPromotionDialog && !autoPromoteToQueen);
// which square a pawn is being promoted to
const [promoteFromSquare, setPromoteFromSquare] = react.useState(null);
const [promoteToSquare, setPromoteToSquare] = react.useState(promotionToSquare);
// current premoves
const [premoves, setPremoves] = react.useState([]);
// ref used to access current value during timeouts (closures)
const premovesRef = react.useRef(premoves);
// current right mouse down square
const [currentRightClickDown, setCurrentRightClickDown] = react.useState();
// chess pieces/styling
const [chessPieces, setChessPieces] = react.useState(Object.assign(Object.assign({}, defaultPieces), customPieces));
// whether the last move was a manual drop or not
const [wasManualDrop, setWasManualDrop] = react.useState(false);
// the most recent timeout whilst waiting for animation to complete
const previousTimeoutRef = react.useRef();
// if currently waiting for an animation to finish
const [isWaitingForAnimation, setIsWaitingForAnimation] = react.useState(false);
// last square dragged over for checking in touch events
const [lastSquareDraggedOver, setLastSquareDraggedOver] = react.useState(null);
// open clearPremoves() to allow user to call on undo/reset/whenever
react.useImperativeHandle(ref, () => ({
clearPremoves(clearLastPieceColour = true) {
clearPremoves(clearLastPieceColour);
},
}));
// handle custom pieces change
react.useEffect(() => {
setChessPieces(Object.assign(Object.assign({}, defaultPieces), customPieces));
}, [customPieces]);
// handle promote changes
react.useEffect(() => {
setShowPromoteDialog(showPromotionDialog);
setPromoteToSquare(promotionToSquare);
}, [promotionToSquare, showPromotionDialog]);
// handle external position change
react.useEffect(() => {
var _a, _b, _c;
// clear any open promotion dialogs
clearPromotion();
const newPosition = convertPositionToObject(position);
const differences = getPositionDifferences(currentPosition, newPosition);
const newPieceColour = ((_a = Object.keys(differences.added)) === null || _a === void 0 ? void 0 : _a.length) <= 2
? (_c = (_b = Object.entries(differences.added)) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c[1][0]
: undefined;
// external move has come in before animation is over
// cancel animation and immediately update position
if (isWaitingForAnimation) {
setCurrentPosition(newPosition);
setIsWaitingForAnimation(false);
arePremovesAllowed && attemptPremove(newPieceColour);
if (previousTimeoutRef.current) {
clearTimeout(previousTimeoutRef.current);
}
}
else {
// move was made using drag and drop
if (wasManualDrop) {
setCurrentPosition(newPosition);
setIsWaitingForAnimation(false);
arePremovesAllowed && attemptPremove(newPieceColour);
}
else {
// move was made by external position change
// if position === start then don't override newPieceColour
// needs isDifferentFromStart in scenario where premoves have been cleared upon board reset but first move is made by computer, the last move colour would need to be updated
if (isDifferentFromStart(newPosition) &&
lastPieceColour !== undefined) {
setLastPieceColour(newPieceColour);
}
else if (!isDifferentFromStart(newPosition)) {
// position === start, likely a board reset. set to black to allow black to make premoves on first move
setLastPieceColour("b");
}
else {
setLastPieceColour(undefined);
}
setPositionDifferences(differences);
// animate external move
setIsWaitingForAnimation(true);
const newTimeout = setTimeout(() => {
setCurrentPosition(newPosition);
setIsWaitingForAnimation(false);
arePremovesAllowed && attemptPremove(newPieceColour);
}, animationDuration);
previousTimeoutRef.current = newTimeout;
}
}
// reset manual drop, ready for next move to be made by user or external
setWasManualDrop(false);
// inform latest position information
getPositionObject(newPosition);
// clear arrows
clearArrows();
// clear timeout on unmount
return () => {
clearTimeout(previousTimeoutRef.current);
};
}, [position]);
const { arrows, newArrow, clearArrows, drawNewArrow, onArrowDrawEnd } = useArrows(customArrows, areArrowsAllowed, onArrowsChange, customArrowColor);
// handle drop position change
function handleSetPosition(sourceSq, targetSq, piece, wasManualDropOverride) {
// if dropped back down, don't do anything
if (sourceSq === targetSq) {
return;
}
clearArrows();
// if second move is made for same colour, or there are still premoves queued, then this move needs to be added to premove queue instead of played
// premoves length check for colour is added in because white could make 3 premoves, and then black responds to the first move (changing the last piece colour) and then white pre-moves again
if ((arePremovesAllowed && isWaitingForAnimation) ||
(arePremovesAllowed &&
(lastPieceColour === piece[0] ||
premovesRef.current.filter((p) => p.piece[0] === piece[0])
.length > 0))) {
const oldPremoves = [...premovesRef.current];
oldPremoves.push({ sourceSq, targetSq, piece });
premovesRef.current = oldPremoves;
setPremoves([...oldPremoves]);
clearPromotion();
return;
}
// if transitioning, don't allow new drop
if (!arePremovesAllowed && isWaitingForAnimation)
return;
const newOnDropPosition = Object.assign({}, currentPosition);
setWasManualDrop(!!wasManualDropOverride);
setLastPieceColour(piece[0]);
// if onPieceDrop function provided, execute it, position must be updated externally and captured by useEffect above for this move to show on board
if (onPieceDrop.length) {
const isValidMove = onPieceDrop(sourceSq, targetSq, piece);
if (!isValidMove) {
clearPremoves();
setWasManualDrop(false);
}
}
else {
// delete source piece
delete newOnDropPosition[sourceSq];
// add piece in new position
newOnDropPosition[targetSq] = piece;
setCurrentPosition(newOnDropPosition);
}
clearPromotion();
// inform latest position information
getPositionObject(newOnDropPosition);
}
function deletePieceFromSquare(square) {
const positionCopy = Object.assign({}, currentPosition);
delete positionCopy[square];
setCurrentPosition(positionCopy);
// inform latest position information
getPositionObject(positionCopy);
}
function attemptPremove(newPieceColour) {
if (premovesRef.current.length === 0)
return;
// get current value of premove as this is called in a timeout so value may have changed since timeout was set
const premove = premovesRef.current[0];
// if premove is a differing colour to last move made, then this move can be made
if (premove.piece[0] !== undefined &&
premove.piece[0] !== newPieceColour &&
onPieceDrop.length) {
setLastPieceColour(premove.piece[0]);
setWasManualDrop(true); // pre-move doesn't need animation
const isValidMove = onPieceDrop(premove.sourceSq, premove.targetSq, premove.piece);
// premove was successful and can be removed from queue
if (isValidMove) {
const oldPremoves = [...premovesRef.current];
oldPremoves.shift();
premovesRef.current = oldPremoves;
setPremoves([...oldPremoves]);
}
else {
// premove wasn't successful, clear premove queue
clearPremoves();
}
}
}
function handleSparePieceDrop(piece, targetSq) {
const isValidDrop = onSparePieceDrop(piece, targetSq);
if (!isValidDrop)
return;
const newOnDropPosition = Object.assign({}, currentPosition);
// add piece in new position
newOnDropPosition[targetSq] = piece;
setCurrentPosition(newOnDropPosition);
// inform latest position information
getPositionObject(newOnDropPosition);
}
function clearPremoves(clearLastPieceColour = true) {
// don't clear when right clicking to clear, otherwise you won't be able to premove again before next go
if (clearLastPieceColour)
setLastPieceColour(undefined);
premovesRef.current = [];
setPremoves([]);
}
function clearPromotion() {
setPromoteFromSquare(null);
setPromoteToSquare(null);
setShowPromoteDialog(false);
}
function onRightClickDown(square) {
setCurrentRightClickDown(square);
}
function onRightClickUp(square) {
if (currentRightClickDown) {
// same square, don't draw an arrow, but do clear premoves and run onSquareRightClick
if (currentRightClickDown === square) {
setCurrentRightClickDown(undefined);
clearPremovesOnRightClick && clearPremoves(false);
onSquareRightClick(square);
return;
}
}
else
setCurrentRightClickDown(undefined);
}
function clearCurrentRightClickDown() {
setCurrentRightClickDown(undefined);
}
const ChessboardProviderContextValue = {
allowDragOutsideBoard,
animationDuration,
arePiecesDraggable,
arePremovesAllowed,
arrows,
autoPromoteToQueen,
boardOrientation,
boardWidth,
chessPieces,
clearArrows,
clearCurrentRightClickDown,
currentPosition,
currentRightClickDown,
customArrowColor,
customBoardStyle,
customDarkSquareStyle,
customDropSquareStyle,
customLightSquareStyle,
customNotationStyle,
customPremoveDarkSquareStyle,
customPremoveLightSquareStyle,
customSquare,
customSquareStyles,
deletePieceFromSquare,
drawNewArrow,
dropOffBoardAction,
handleSetPosition,
handleSparePieceDrop,
id,
isDraggablePiece,
isWaitingForAnimation,
lastPieceColour,
lastSquareDraggedOver,
newArrow,
onArrowDrawEnd,
onDragOverSquare,
onMouseOutSquare,
onMouseOverSquare,
onPieceClick,
onPieceDragBegin,
onPieceDragEnd,
onPieceDrop,
onPieceDropOffBoard,
onPromotionCheck,
onPromotionPieceSelect,
onRightClickDown,
onRightClickUp,
onSparePieceDrop,
onSquareClick,
positionDifferences,
premoves,
promoteFromSquare,
promoteToSquare,
promotionDialogVariant,
setLastSquareDraggedOver,
setPromoteFromSquare,
setPromoteToSquare,
setShowPromoteDialog,
showBoardNotation,
showPromoteDialog,
snapToCursor,
};
return (jsxRuntime.jsx(ChessboardContext.Provider, Object.assign({ value: ChessboardProviderContextValue }, { children: children })));
});
function Notation({ row, col }) {
const { boardOrientation, boardWidth, customDarkSquareStyle, customLightSquareStyle, customNotationStyle, } = useChessboard();
const whiteColor = customLightSquareStyle.backgroundColor;
const blackColor = customDarkSquareStyle.backgroundColor;
const isRow = col === 0;
const isColumn = row === 7;
const isBottomLeftSquare = isRow && isColumn;
function getRow() {
return boardOrientation === "white" ? 8 - row : row + 1;
}
function getColumn() {
return boardOrientation === "black" ? COLUMNS[7 - col] : COLUMNS[col];
}
function renderBottomLeft() {
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("div", Object.assign({ style: Object.assign(Object.assign({ zIndex: 3, position: "absolute" }, { color: whiteColor }), numericStyle(boardWidth, customNotationStyle)) }, { children: getRow() })), jsxRuntime.jsx("div", Object.assign({ style: Object.assign(Object.assign({ zIndex: 3, position: "absolute" }, { color: whiteColor }), alphaStyle(boardWidth, customNotationStyle)) }, { children: getColumn() }))] }));
}
function renderLetters() {
return (jsxRuntime.jsx("div", Object.assign({ style: Object.assign(Object.assign({ userSelect: "none", zIndex: 3, position: "absolute" }, { color: col % 2 !== 0 ? blackColor : whiteColor }), alphaStyle(boardWidth, customNotationStyle)) }, { children: getColumn() })));
}
function renderNumbers() {
return (jsxRuntime.jsx("div", Object.assign({ style: Object.assign(Object.assign({ userSelect: "none", zIndex: 3, position: "absolute" }, (boardOrientation === "black"
? { color: row % 2 === 0 ? blackColor : whiteColor }
: { color: row % 2 === 0 ? blackColor : whiteColor })), numericStyle(boardWidth, customNotationStyle)) }, { children: getRow() })));
}
if (isBottomLeftSquare) {
return renderBottomLeft();
}
if (isColumn) {
return renderLetters();
}
if (isRow) {
return renderNumbers();
}
return null;
}
const alphaStyle = (width, customNotationStyle) => (Object.assign({ alignSelf: "flex-end", paddingLeft: width / 8 - width / 48, fontSize: width / 48 }, customNotationStyle));
const numericStyle = (width, customNotationStyle) => (Object.assign({ alignSelf: "flex-start", paddingRight: width / 8 - width / 48, fontSize: width / 48 }, customNotationStyle));
/**
* Create the React Context
*/ const DndContext = react.createContext({
dragDropManager: undefined
});
/**
* Adapted from React: https://github.com/facebook/react/blob/master/packages/shared/formatProdErrorMessage.js
*
* Do not require this module directly! Use normal throw error calls. These messages will be replaced with error codes
* during build.
* @param {number} code
*/
function formatProdErrorMessage(code) {
return "Minified Redux error #" + code + "; visit https://redux.js.org/Errors?code=" + code + " for the full message or " + 'use the non-minified dev environment for full errors. ';
}
// Inlined version of the `symbol-observable` polyfill
var $$observable = (function () {
return typeof Symbol === 'function' && Symbol.observable || '@@observable';
})();
/**
* These are private action types reserved by Redux.
* For any unknown actions, you must return the current state.
* If the current state is undefined, you must return the initial state.
* Do not reference these action types directly in your code.
*/
var randomString = function randomString() {
return Math.random().toString(36).substring(7).split('').join('.');
};
var ActionTypes = {
INIT: "@@redux/INIT" + randomString(),
REPLACE: "@@redux/REPLACE" + randomString(),
PROBE_UNKNOWN_ACTION: function PROBE_UNKNOWN_ACTION() {
return "@@redux/PROBE_UNKNOWN_ACTION" + randomString();
}
};
/**
* @param {any} obj The object to inspect.
* @returns {boolean} True if the argument appears to be a plain object.
*/
function isPlainObject(obj) {
if (typeof obj !== 'object' || obj === null) return false;
var proto = obj;
while (Object.getPrototypeOf(proto) !== null) {
proto = Object.getPrototypeOf(proto);
}
return Object.getPrototypeOf(obj) === proto;
}
// Inlined / shortened version of `kindOf` from https://github.com/jonschlinkert/kind-of
function miniKindOf(val) {
if (val === void 0) return 'undefined';
if (val === null) return 'null';
var type = typeof val;
switch (type) {
case 'boolean':
case 'string':
case 'number':
case 'symbol':
case 'function':
{
return type;
}
}
if (Array.isArray(val)) return 'array';
if (isDate(val)) return 'date';
if (isError(val)) return 'error';
var constructorName = ctorName(val);
switch (constructorName) {
case 'Symbol':
case 'Promise':
case 'WeakMap':
case 'WeakSet':
case 'Map':
case 'Set':
return constructorName;
} // other
return type.slice(8, -1).toLowerCase().replace(/\s/g, '');
}
function ctorName(val) {
return typeof val.constructor === 'function' ? val.constructor.name : null;
}
function isError(val) {
return val instanceof Error || typeof val.message === 'string' && val.constructor && typeof val.constructor.stackTraceLimit === 'number';
}
function isDate(val) {
if (val instanceof Date) return true;
return typeof val.toDateString === 'function' && typeof val.getDate === 'function' && typeof val.setDate === 'function';
}
function kindOf(val) {
var typeOfVal = typeof val;
if (process.env.NODE_ENV !== 'production') {
typeOfVal = miniKindOf(val);
}
return typeOfVal;
}
/**
* @deprecated
*
* **We recommend using the `configureStore` method
* of the `@reduxjs/toolkit` package**, which replaces `createStore`.
*
* Redux Toolkit is our recommended approach for writing Redux logic today,
* including store setup, reducers, data fetching, and more.
*
* **For more details, please read this Redux docs