120 lines
9.3 KiB
TypeScript
120 lines
9.3 KiB
TypeScript
/**
|
|||
|
|
* High-quality vector SVGs for standard Chess pieces (Staunton design).
|
||
|
|
* Provides clean, crisp rendering at all DPRs and sizes.
|
||
|
|
*/
|
||
|
|
|
||
|
|
export type PieceType = "k" | "q" | "r" | "b" | "n" | "p";
|
||
|
|
export type PieceColor = "w" | "b";
|
||
|
|
|
||
|
|
const PIECE_SVGS: Record<PieceType, { w: string; b: string }> = {
|
||
|
|
k: {
|
||
|
|
w: `<svg viewBox="0 0 45 45" class="piece-svg piece-w" xmlns="http://www.w3.org/2000/svg">
|
||
|
|
<g fill="none" fill-rule="evenodd" stroke="#222" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">
|
||
|
|
<path d="M22.5 11.63V6M20 8h5" stroke-linejoin="miter"/>
|
||
|
|
<path d="M22.5 25s4.5-7.5 3-10.5c0 0-1-2.5-3-2.5s-3 2.5-3 2.5c-1.5 3 3 10.5 3 10.5" fill="#fff" stroke-linecap="butt" stroke-linejoin="miter"/>
|
||
|
|
<path d="M11.5 37c5.5 3.5 15.5 3.5 21 0v-7s9-4.5 6-10.5c-4-6.5-13.5-3.5-16 4V23.5c-2.5-7.5-12-10.5-16-4-3 6 6 10.5 6 10.5v7z" fill="#fff"/>
|
||
|
|
<path d="M11.5 30c5.5-3 15.5-3 21 0m-21 3.5c5.5-3 15.5-3 21 0m-21 3.5c5.5-3 15.5-3 21 0"/>
|
||
|
|
</g>
|
||
|
|
</svg>`,
|
||
|
|
b: `<svg viewBox="0 0 45 45" class="piece-svg piece-b" xmlns="http://www.w3.org/2000/svg">
|
||
|
|
<g fill="none" fill-rule="evenodd" stroke="#222" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">
|
||
|
|
<path d="M22.5 11.63V6M20 8h5" stroke="#fff" stroke-linejoin="miter"/>
|
||
|
|
<path d="M22.5 25s4.5-7.5 3-10.5c0 0-1-2.5-3-2.5s-3 2.5-3 2.5c-1.5 3 3 10.5 3 10.5" fill="#2d3038" stroke-linecap="butt" stroke-linejoin="miter"/>
|
||
|
|
<path d="M11.5 37c5.5 3.5 15.5 3.5 21 0v-7s9-4.5 6-10.5c-4-6.5-13.5-3.5-16 4V23.5c-2.5-7.5-12-10.5-16-4-3 6 6 10.5 6 10.5v7z" fill="#2d3038"/>
|
||
|
|
<path d="M11.5 30c5.5-3 15.5-3 21 0m-21 3.5c5.5-3 15.5-3 21 0m-21 3.5c5.5-3 15.5-3 21 0" stroke="#fff"/>
|
||
|
|
</g>
|
||
|
|
</svg>`,
|
||
|
|
},
|
||
|
|
q: {
|
||
|
|
w: `<svg viewBox="0 0 45 45" class="piece-svg piece-w" xmlns="http://www.w3.org/2000/svg">
|
||
|
|
<g fill="#fff" fill-rule="evenodd" stroke="#222" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">
|
||
|
|
<path d="M8 12a2 2 0 1 1-4 0 2 2 0 1 1 4 0zm16.5-4.5a2 2 0 1 1-4 0 2 2 0 1 1 4 0zM41 12a2 2 0 1 1-4 0 2 2 0 1 1 4 0zM16 8.5a2 2 0 1 1-4 0 2 2 0 1 1 4 0zm17 0a2 2 0 1 1-4 0 2 2 0 1 1 4 0z"/>
|
||
|
|
<path d="M9 26c8.5-1.5 21-1.5 27 0l2-12-7 11V11l-5.5 13.5-3-15-3 15-5.5-13.5V25L7 14l2 12z" stroke-linecap="butt"/>
|
||
|
|
<path d="M9 26c0 2 1.5 2 2.5 4 1 1.5 1 1 .5 3.5-1.5 1-1.5 2.5-1.5 2.5-1.5 1.5.5 2.5.5 2.5 6.5 1 16.5 1 23 0 0 0 2-1 .5-2.5 0 0 0-1.5-1.5-2.5-.5-2.5-.5-2 .5-3.5 1-2 2.5-2 2.5-4-8.5-1.5-18.5-1.5-27 0z" stroke-linecap="butt"/>
|
||
|
|
<path d="M11 38.5a35 35 1 0 0 23 0" fill="none" stroke-linecap="butt"/>
|
||
|
|
<path d="M11 29a35 35 1 0 1 23 0M12.5 31.5h20M11.5 34.5a35 35 1 0 0 22 0M10.5 37.5a35 35 1 0 0 24 0" fill="none"/>
|
||
|
|
</g>
|
||
|
|
</svg>`,
|
||
|
|
b: `<svg viewBox="0 0 45 45" class="piece-svg piece-b" xmlns="http://www.w3.org/2000/svg">
|
||
|
|
<g fill="#2d3038" fill-rule="evenodd" stroke="#222" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">
|
||
|
|
<path d="M8 12a2 2 0 1 1-4 0 2 2 0 1 1 4 0zm16.5-4.5a2 2 0 1 1-4 0 2 2 0 1 1 4 0zM41 12a2 2 0 1 1-4 0 2 2 0 1 1 4 0zM16 8.5a2 2 0 1 1-4 0 2 2 0 1 1 4 0zm17 0a2 2 0 1 1-4 0 2 2 0 1 1 4 0z"/>
|
||
|
|
<path d="M9 26c8.5-1.5 21-1.5 27 0l2-12-7 11V11l-5.5 13.5-3-15-3 15-5.5-13.5V25L7 14l2 12z" stroke-linecap="butt"/>
|
||
|
|
<path d="M9 26c0 2 1.5 2 2.5 4 1 1.5 1 1 .5 3.5-1.5 1-1.5 2.5-1.5 2.5-1.5 1.5.5 2.5.5 2.5 6.5 1 16.5 1 23 0 0 0 2-1 .5-2.5 0 0 0-1.5-1.5-2.5-.5-2.5-.5-2 .5-3.5 1-2 2.5-2 2.5-4-8.5-1.5-18.5-1.5-27 0z" stroke-linecap="butt"/>
|
||
|
|
<path d="M11 38.5a35 35 1 0 0 23 0" fill="none" stroke="#fff" stroke-linecap="butt"/>
|
||
|
|
<path d="M11 29a35 35 1 0 1 23 0M12.5 31.5h20M11.5 34.5a35 35 1 0 0 22 0M10.5 37.5a35 35 1 0 0 24 0" fill="none" stroke="#fff"/>
|
||
|
|
</g>
|
||
|
|
</svg>`,
|
||
|
|
},
|
||
|
|
r: {
|
||
|
|
w: `<svg viewBox="0 0 45 45" class="piece-svg piece-w" xmlns="http://www.w3.org/2000/svg">
|
||
|
|
<g fill="#fff" fill-rule="evenodd" stroke="#222" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">
|
||
|
|
<path d="M9 39h27v-3H9v3zm3-3v-4.5h21V36H12zm2-4.5v-11h17v11H14z" stroke-linecap="butt"/>
|
||
|
|
<path d="M14 20.5h17M11 14h23l-2.5 6.5h-18L11 14z"/>
|
||
|
|
<path d="M12 10.5h4v3.5h-4zm7 0h7v3.5h-7zm10 0h4v3.5h-4z" stroke-linecap="butt"/>
|
||
|
|
<path d="M14 29.5v-1h17v1H14zm-1 3.5v-1h19v1H13z" fill="none"/>
|
||
|
|
</g>
|
||
|
|
</svg>`,
|
||
|
|
b: `<svg viewBox="0 0 45 45" class="piece-svg piece-b" xmlns="http://www.w3.org/2000/svg">
|
||
|
|
<g fill="#2d3038" fill-rule="evenodd" stroke="#222" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">
|
||
|
|
<path d="M9 39h27v-3H9v3zm3-3v-4.5h21V36H12zm2-4.5v-11h17v11H14z" stroke-linecap="butt"/>
|
||
|
|
<path d="M14 20.5h17M11 14h23l-2.5 6.5h-18L11 14z"/>
|
||
|
|
<path d="M12 10.5h4v3.5h-4zm7 0h7v3.5h-7zm10 0h4v3.5h-4z" stroke-linecap="butt"/>
|
||
|
|
<path d="M14 29.5v-1h17v1H14zm-1 3.5v-1h19v1H13z" fill="none" stroke="#fff"/>
|
||
|
|
</g>
|
||
|
|
</svg>`,
|
||
|
|
},
|
||
|
|
b: {
|
||
|
|
w: `<svg viewBox="0 0 45 45" class="piece-svg piece-w" xmlns="http://www.w3.org/2000/svg">
|
||
|
|
<g fill="none" fill-rule="evenodd" stroke="#222" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">
|
||
|
|
<g fill="#fff">
|
||
|
|
<path d="M9 36c3.39-.97 10.11.43 13.5-2 3.39 2.43 10.11 1.03 13.5 2 0 0 1.65.54 3 2-.68.97-1.65.99-3 .5-3.39-.97-10.11.46-13.5-1-3.39 1.46-10.11.03-13.5 1-1.35.49-2.32.47-3-.5 1.35-1.94 3-2 3-2z"/>
|
||
|
|
<path d="M15 32c2.5 2.5 12.5 2.5 15 0 .5-1.5 0-2 0-2 0-2.5-2.5-4-2.5-4 5.5-1.5 6-11.5-5-15.5-11 4-10.5 14-5 15.5 0 0-2.5 1.5-2.5 4 0 0-.5.5 0 2z"/>
|
||
|
|
<path d="M25 8a2.5 2.5 0 1 1-5 0 2.5 2.5 0 1 1 5 0z"/>
|
||
|
|
</g>
|
||
|
|
<path d="M17.5 26h10M15 30h15M22.5 15.5v5M20 18h5" stroke-linejoin="miter"/>
|
||
|
|
</g>
|
||
|
|
</svg>`,
|
||
|
|
b: `<svg viewBox="0 0 45 45" class="piece-svg piece-b" xmlns="http://www.w3.org/2000/svg">
|
||
|
|
<g fill="none" fill-rule="evenodd" stroke="#222" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">
|
||
|
|
<g fill="#2d3038">
|
||
|
|
<path d="M9 36c3.39-.97 10.11.43 13.5-2 3.39 2.43 10.11 1.03 13.5 2 0 0 1.65.54 3 2-.68.97-1.65.99-3 .5-3.39-.97-10.11.46-13.5-1-3.39 1.46-10.11.03-13.5 1-1.35.49-2.32.47-3-.5 1.35-1.94 3-2 3-2z"/>
|
||
|
|
<path d="M15 32c2.5 2.5 12.5 2.5 15 0 .5-1.5 0-2 0-2 0-2.5-2.5-4-2.5-4 5.5-1.5 6-11.5-5-15.5-11 4-10.5 14-5 15.5 0 0-2.5 1.5-2.5 4 0 0-.5.5 0 2z"/>
|
||
|
|
<path d="M25 8a2.5 2.5 0 1 1-5 0 2.5 2.5 0 1 1 5 0z"/>
|
||
|
|
</g>
|
||
|
|
<path d="M17.5 26h10M15 30h15M22.5 15.5v5M20 18h5" stroke="#fff" stroke-linejoin="miter"/>
|
||
|
|
</g>
|
||
|
|
</svg>`,
|
||
|
|
},
|
||
|
|
n: {
|
||
|
|
w: `<svg viewBox="0 0 45 45" class="piece-svg piece-w" xmlns="http://www.w3.org/2000/svg">
|
||
|
|
<g fill="none" fill-rule="evenodd" stroke="#222" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">
|
||
|
|
<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" fill="#fff"/>
|
||
|
|
<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,7.4 17.03,5.16 20,6 C 22,6.5 21.84,7.85 22,10 z" fill="#fff"/>
|
||
|
|
<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" fill="#222" stroke="#222"/>
|
||
|
|
<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)" fill="#222" stroke="#222"/>
|
||
|
|
</g>
|
||
|
|
</svg>`,
|
||
|
|
b: `<svg viewBox="0 0 45 45" class="piece-svg piece-b" xmlns="http://www.w3.org/2000/svg">
|
||
|
|
<g fill="none" fill-rule="evenodd" stroke="#222" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">
|
||
|
|
<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" fill="#2d3038"/>
|
||
|
|
<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,7.4 17.03,5.16 20,6 C 22,6.5 21.84,7.85 22,10 z" fill="#2d3038"/>
|
||
|
|
<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" fill="#fff" stroke="#fff"/>
|
||
|
|
<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)" fill="#fff" stroke="#fff"/>
|
||
|
|
</g>
|
||
|
|
</svg>`,
|
||
|
|
},
|
||
|
|
p: {
|
||
|
|
w: `<svg viewBox="0 0 45 45" class="piece-svg piece-w" xmlns="http://www.w3.org/2000/svg">
|
||
|
|
<path d="M22.5 9c-2.21 0-4 1.79-4 4 0 .89.29 1.71.78 2.38C17.33 16.5 16 18.59 16 21c0 2.03.94 3.84 2.41 5.03-3 1.06-7.41 5.55-7.41 13.47h23c0-7.92-4.41-12.41-7.41-13.47 1.47-1.19 2.41-3 2.41-5.03 0-2.41-1.33-4.5-3.28-5.62.49-.67.78-1.49.78-2.38 0-2.21-1.79-4-4-4z" fill="#fff" stroke="#222" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
|
||
|
|
</svg>`,
|
||
|
|
b: `<svg viewBox="0 0 45 45" class="piece-svg piece-b" xmlns="http://www.w3.org/2000/svg">
|
||
|
|
<path d="M22.5 9c-2.21 0-4 1.79-4 4 0 .89.29 1.71.78 2.38C17.33 16.5 16 18.59 16 21c0 2.03.94 3.84 2.41 5.03-3 1.06-7.41 5.55-7.41 13.47h23c0-7.92-4.41-12.41-7.41-13.47 1.47-1.19 2.41-3 2.41-5.03 0-2.41-1.33-4.5-3.28-5.62.49-.67.78-1.49.78-2.38 0-2.21-1.79-4-4-4z" fill="#2d3038" stroke="#222" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
|
||
|
|
</svg>`,
|
||
|
|
},
|
||
|
|
};
|
||
|
|
|
||
|
|
export function getPieceSvg(type: PieceType | null, color: PieceColor | null): string {
|
||
|
|
if (!type || !color) return "";
|
||
|
|
return PIECE_SVGS[type]?.[color] ?? "";
|
||
|
|
}
|