npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-shogi-board

v0.1.0

Published

React components for rendering and playing Shogi (Japanese Chess)

Readme

react-shogi-board

React 製の将棋盤コンポーネントライブラリです。

  • 対局盤・棋譜再生・ローレベル盤面表示の 3 コンポーネント
  • SFEN による局面の初期化・外部からの駒操作
  • shogi.js / json-kifu-format ベース

インストール

npm install react-shogi-board shogi.js json-kifu-format

スタイルを適用するため、エントリポイントで CSS をインポートしてください。

import "react-shogi-board/styles";

コンポーネント

<InteractiveBoard>

ユーザーが駒を操作して対局できるインタラクティブな盤面です。
外部から ref を通じて駒を動かすこともできます(AI 対局など)。

import { useRef } from "react";
import { InteractiveBoard, type InteractiveBoardHandle } from "react-shogi-board";

function App() {
  const ref = useRef<InteractiveBoardHandle>(null);

  return (
    <InteractiveBoard
      ref={ref}
      initialSfen="lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL b - 1"
      onChange={(sfen) => console.log("現在の局面:", sfen)}
      flipped={false}
    />
  );
}

// 外部から駒を動かす(例: AI の指し手)
ref.current?.move(7, 7, 7, 6);

// 初期局面に戻す
ref.current?.reset();

Props

| Prop | 型 | デフォルト | 説明 | |------|-----|-----------|------| | initialSfen | string | 平手初期配置 | 初期局面の SFEN 文字列 | | onChange | (sfen: string) => void | — | 盤面が変化するたびに現在の SFEN を通知 | | flipped | boolean | false | true で後手視点に反転 |

InteractiveBoardHandle(ref)

| メソッド | 説明 | |----------|------| | move(fromX, fromY, toX, toY, promote?) | 外部から駒を動かす | | reset() | initialSfen(省略時は平手)に戻す |


<KifuPlayer>

棋譜文字列を渡すと再生コントロール付きの棋譜プレイヤーになります。

import { KifuPlayer } from "react-shogi-board";

<KifuPlayer
  kifu={kifuString}
  format="kif"
  autoPlayInterval={800}
  flipped={false}
/>

Props

| Prop | 型 | デフォルト | 説明 | |------|-----|-----------|------| | kifu | string | 必須 | 棋譜文字列 | | format | "kif" \| "ki2" \| "csa" \| "jkf" | 自動判定 | 棋譜フォーマット | | autoPlayInterval | number | 1000 | 自動再生の間隔 (ms) | | flipped | boolean | false | true で後手視点に反転 |

キーボードショートカット: / で 1 手移動、Space で再生/停止、Home / End で先頭/末尾。


<ShogiBoard>

局面表示のみを担うローレベルコンポーネントです。
状態管理は呼び出し側で行います。

import { ShogiBoard } from "react-shogi-board";
import { Shogi } from "shogi.js";

const shogi = new Shogi();

<ShogiBoard
  shogi={shogi}
  selectedSquare={{ x: 7, y: 7 }}
  legalSquares={[{ x: 7, y: 6 }]}
  lastMove={{ x: 7, y: 6 }}
  onSquareClick={(pos) => console.log(pos)}
  onHandClick={(kind, color) => console.log(kind, color)}
  flipped={false}
/>

Props

| Prop | 型 | デフォルト | 説明 | |------|-----|-----------|------| | shogi | Shogi | 必須 | shogi.js の Shogi インスタンス | | selectedSquare | SquarePos \| null | — | 選択中のマス | | legalSquares | SquarePos[] | [] | 移動可能なマス一覧(ハイライト表示) | | lastMove | SquarePos \| null | — | 直前の指し手の移動先 | | onSquareClick | (pos: SquarePos) => void | — | マスクリック時のコールバック | | onHandClick | (kind: Kind, color: 0 \| 1) => void | — | 持ち駒クリック時のコールバック | | flipped | boolean | false | true で後手視点に反転 |


Hooks

useShogiGame

InteractiveBoard の内部で使用している対局管理フックです。
盤面の状態管理を自前で行いたい場合に直接使えます。

import { useShogiGame } from "react-shogi-board";

const {
  shogi,
  selectedSquare,
  legalSquares,
  lastMove,
  promotionPending,
  onSquareClick,
  onHandClick,
  onPromote,
  reset,
  moveExternal,
} = useShogiGame({
  initialSfen: "...",
  onChange: (sfen) => console.log(sfen),
});

オプション

| オプション | 型 | 説明 | |------------|-----|------| | initialSfen | string | 初期局面の SFEN 文字列 | | onChange | (sfen: string) => void | 盤面変化時のコールバック |


useKifuPlayer

KifuPlayer の内部で使用している棋譜再生フックです。
独自の再生 UI を構築したい場合に使えます。

import { useKifuPlayer } from "react-shogi-board";

const {
  player,        // JKFPlayer インスタンス(player.shogi で局面を取得)
  currentMove,   // 現在の手数
  totalMoves,    // 総手数
  lastMoveTo,    // 直前の指し手の移動先
  moveDescription, // 指し手のテキスト表現
  goNext,
  goPrev,
  goTo,
  goFirst,
  goLast,
} = useKifuPlayer({ kifu: kifuString, format: "kif" });

import type {
  SquarePos,
  ShogiBoardProps,
  InteractiveBoardProps,
  InteractiveBoardHandle,
  KifuPlayerProps,
  UseShogiGameOptions,
  UseShogiGameReturn,
  UseKifuPlayerOptions,
  UseKifuPlayerReturn,
  KifuFormat,
} from "react-shogi-board";