@hackersheet/next-document-content-kifu 0.1.0-alpha.15 → 0.1.0-alpha.17

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.
Files changed (46) hide show
  1. package/dist/cjs/components/kifu/kifu.js +2 -2
  2. package/dist/cjs/components/shogi-player/adapters/kifu-adapter.d.ts +11 -0
  3. package/dist/cjs/components/shogi-player/adapters/kifu-adapter.js +104 -0
  4. package/dist/cjs/components/shogi-player/board-renderer.d.ts +60 -0
  5. package/dist/cjs/components/shogi-player/board-renderer.js +137 -0
  6. package/dist/cjs/components/shogi-player/button.d.ts +22 -1
  7. package/dist/cjs/components/shogi-player/button.js +2 -1
  8. package/dist/cjs/components/shogi-player/canvas-utils.d.ts +29 -0
  9. package/dist/cjs/components/shogi-player/{index.js → canvas-utils.js} +26 -16
  10. package/dist/cjs/components/shogi-player/hands-renderer.d.ts +42 -0
  11. package/dist/cjs/components/shogi-player/hands-renderer.js +86 -0
  12. package/dist/cjs/components/shogi-player/moves-area.d.ts +24 -3
  13. package/dist/cjs/components/shogi-player/moves-area.js +15 -20
  14. package/dist/cjs/components/shogi-player/shogi-board-canvas.d.ts +20 -13
  15. package/dist/cjs/components/shogi-player/shogi-board-canvas.js +9 -119
  16. package/dist/cjs/components/shogi-player/shogi-hands-canvas.d.ts +20 -12
  17. package/dist/cjs/components/shogi-player/shogi-hands-canvas.js +7 -79
  18. package/dist/cjs/components/shogi-player/shogi-player.d.ts +22 -0
  19. package/dist/cjs/components/shogi-player/shogi-player.js +51 -41
  20. package/dist/cjs/components/shogi-player/types.d.ts +169 -0
  21. package/dist/cjs/components/shogi-player/types.js +16 -0
  22. package/dist/esm/components/kifu/kifu.mjs +1 -1
  23. package/dist/esm/components/shogi-player/adapters/kifu-adapter.d.mts +11 -0
  24. package/dist/esm/components/shogi-player/adapters/kifu-adapter.mjs +80 -0
  25. package/dist/esm/components/shogi-player/board-renderer.d.mts +60 -0
  26. package/dist/esm/components/shogi-player/board-renderer.mjs +109 -0
  27. package/dist/esm/components/shogi-player/button.d.mts +22 -1
  28. package/dist/esm/components/shogi-player/button.mjs +2 -1
  29. package/dist/esm/components/shogi-player/canvas-utils.d.mts +29 -0
  30. package/dist/esm/components/shogi-player/canvas-utils.mjs +22 -0
  31. package/dist/esm/components/shogi-player/hands-renderer.d.mts +42 -0
  32. package/dist/esm/components/shogi-player/hands-renderer.mjs +60 -0
  33. package/dist/esm/components/shogi-player/moves-area.d.mts +24 -3
  34. package/dist/esm/components/shogi-player/moves-area.mjs +16 -17
  35. package/dist/esm/components/shogi-player/shogi-board-canvas.d.mts +20 -13
  36. package/dist/esm/components/shogi-player/shogi-board-canvas.mjs +12 -116
  37. package/dist/esm/components/shogi-player/shogi-hands-canvas.d.mts +20 -12
  38. package/dist/esm/components/shogi-player/shogi-hands-canvas.mjs +4 -76
  39. package/dist/esm/components/shogi-player/shogi-player.d.mts +22 -0
  40. package/dist/esm/components/shogi-player/shogi-player.mjs +52 -42
  41. package/dist/esm/components/shogi-player/types.d.mts +169 -0
  42. package/dist/esm/components/shogi-player/types.mjs +0 -0
  43. package/package.json +3 -3
  44. package/dist/cjs/components/shogi-player/index.d.ts +0 -2
  45. package/dist/esm/components/shogi-player/index.d.mts +0 -2
  46. package/dist/esm/components/shogi-player/index.mjs +0 -4
@@ -0,0 +1,169 @@
1
+ import { Piece } from 'shogi.js';
2
+
3
+ /**
4
+ * Library-independent move representation
5
+ * @property from - Source position (optional for drops)
6
+ * @property to - Destination position
7
+ * @property color - Player color (0: sente/black, 1: gote/white)
8
+ * @property piece - Piece type being moved
9
+ * @property same - Whether the destination is the same as the previous move
10
+ * @property promote - Whether the piece promotes
11
+ * @property capture - Captured piece type (if any)
12
+ * @property relative - Relative movement direction (for disambiguation)
13
+ */
14
+ interface Move {
15
+ from?: {
16
+ x: number;
17
+ y: number;
18
+ };
19
+ to?: {
20
+ x: number;
21
+ y: number;
22
+ };
23
+ color?: number;
24
+ piece?: string;
25
+ same?: boolean;
26
+ promote?: boolean;
27
+ capture?: string;
28
+ relative?: string;
29
+ }
30
+ /**
31
+ * Complete game state representation independent of external libraries
32
+ * @property board - 9x9 board with pieces (or null for empty squares)
33
+ * @property hands - Captured pieces for each player [sente, gote]
34
+ * @property currentMoveIndex - Current position in the move sequence
35
+ * @property maxMoveIndex - Total number of moves in the game
36
+ * @property currentMove - The move at the current position
37
+ * @property header - Game metadata (player names, date, etc.)
38
+ * @property comments - Comments for the current position
39
+ * @property readableMoves - Human-readable move strings (e.g., "☗7六歩")
40
+ */
41
+ interface GameState {
42
+ board: (Piece | null)[][];
43
+ hands: [Piece[], Piece[]];
44
+ currentMoveIndex: number;
45
+ maxMoveIndex: number;
46
+ currentMove?: Move;
47
+ header: {
48
+ senteName: string;
49
+ goteName: string;
50
+ [key: string]: string;
51
+ };
52
+ comments: string[];
53
+ readableMoves: string[];
54
+ }
55
+ /**
56
+ * Adapter interface for kifu parsing libraries
57
+ * Wraps the underlying library and provides a clean interface for game navigation
58
+ */
59
+ interface KifuAdapter {
60
+ /**
61
+ * Move forward one step in the game
62
+ * @returns Updated game state after the move
63
+ */
64
+ forward(): GameState;
65
+ /**
66
+ * Move backward one step in the game
67
+ * @returns Updated game state after the move
68
+ */
69
+ backward(): GameState;
70
+ /**
71
+ * Jump to a specific move index
72
+ * @param moveIndex - Target move index (0 = initial position)
73
+ * @returns Updated game state after navigation
74
+ */
75
+ goto(moveIndex: number): GameState;
76
+ /**
77
+ * Get the current game state without navigation
78
+ * @returns Current game state
79
+ */
80
+ getState(): GameState;
81
+ /**
82
+ * Clean up resources held by the adapter
83
+ */
84
+ dispose(): void;
85
+ }
86
+ /**
87
+ * Factory function type for creating KifuAdapter instances
88
+ * Used for dependency injection in tests
89
+ */
90
+ type KifuAdapterFactory = (kifuText: string) => KifuAdapter;
91
+ /**
92
+ * Props for ShogiBoardCanvas component
93
+ * @property size - Canvas size in CSS pixels (default: 360)
94
+ * @property boardColor - Background color of the board (default: '#f9d27a')
95
+ * @property lineColor - Color of board lines (default: '#000')
96
+ * @property fontFamily - Font family for coordinates and pieces (default: 'serif')
97
+ * @property fontSizeRatio - Font size ratio relative to cell size (default: 0.7)
98
+ * @property pieces - 2D array of pieces on the board (null for empty squares)
99
+ * @property isSente - Whether to display from black player's perspective (default: true)
100
+ * @property currentMove - Current move to highlight on the board
101
+ */
102
+ type ShogiBoardCanvasProps = {
103
+ size?: number;
104
+ boardColor?: string;
105
+ lineColor?: string;
106
+ fontFamily?: string;
107
+ fontSizeRatio?: number;
108
+ pieces: (Piece | null)[][];
109
+ isSente?: boolean;
110
+ currentMove?: Move;
111
+ };
112
+ /**
113
+ * Props for ShogiHandsCanvas component
114
+ * @property size - Canvas size in CSS pixels (default: 360)
115
+ * @property boardColor - Background color (default: '#f9d27a')
116
+ * @property lineColor - Color of frame lines (default: '#000')
117
+ * @property fontFamily - Font family for piece names (default: 'serif')
118
+ * @property fontSizeRatio - Font size ratio relative to cell size (default: 0.7)
119
+ * @property hands - 2D array of captured pieces
120
+ * @property isSente - Whether to display from black player's perspective (default: true)
121
+ * @property isTop - Whether this is the top hands area (default: false)
122
+ */
123
+ type ShogiHandsCanvasProps = {
124
+ size?: number;
125
+ boardColor?: string;
126
+ lineColor?: string;
127
+ fontFamily?: string;
128
+ fontSizeRatio?: number;
129
+ hands: Piece[][];
130
+ isSente?: boolean;
131
+ isTop?: boolean;
132
+ };
133
+ /**
134
+ * Canvas rendering dimensions including device pixel ratio
135
+ * @property width - Actual canvas width in device pixels
136
+ * @property height - Actual canvas height in device pixels
137
+ * @property dpr - Device pixel ratio for HiDPI displays
138
+ */
139
+ type CanvasDimensions = {
140
+ width: number;
141
+ height: number;
142
+ dpr: number;
143
+ };
144
+ /**
145
+ * Layout information for the shogi board
146
+ * @property margin - Margin from canvas edge
147
+ * @property boardSize - Total size of the 9x9 board area
148
+ * @property cell - Size of a single cell in the board
149
+ */
150
+ type BoardLayout = {
151
+ margin: number;
152
+ boardSize: number;
153
+ cell: number;
154
+ };
155
+ /**
156
+ * Layout information for the hands (captured pieces) area
157
+ * @property margin - Margin from canvas edge
158
+ * @property handsHeight - Total height of the hands canvas
159
+ * @property boardSize - Width of the hands area (same as board width)
160
+ * @property cellSize - Size of a single cell in the hands area
161
+ */
162
+ type HandsLayout = {
163
+ margin: number;
164
+ handsHeight: number;
165
+ boardSize: number;
166
+ cellSize: number;
167
+ };
168
+
169
+ export type { BoardLayout, CanvasDimensions, GameState, HandsLayout, KifuAdapter, KifuAdapterFactory, Move, ShogiBoardCanvasProps, ShogiHandsCanvasProps };
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hackersheet/next-document-content-kifu",
3
- "version": "0.1.0-alpha.15",
3
+ "version": "0.1.0-alpha.17",
4
4
  "description": "Hacker Sheet document content kifu components for Next.js",
5
5
  "keywords": [],
6
6
  "repository": {
@@ -26,8 +26,8 @@
26
26
  "dependencies": {
27
27
  "json-kifu-format": "^5.4.1",
28
28
  "shogi.js": "^5.4.1",
29
- "@hackersheet/core": "0.1.0-alpha.11",
30
- "@hackersheet/react-document-content": "0.1.0-alpha.13"
29
+ "@hackersheet/core": "0.1.0-alpha.12",
30
+ "@hackersheet/react-document-content": "0.1.0-alpha.14"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@types/react": "^19.2.0",
@@ -1,2 +0,0 @@
1
- export { default as ShogiPlayer } from './shogi-player.js';
2
- import 'react';
@@ -1,2 +0,0 @@
1
- export { default as ShogiPlayer } from './shogi-player.mjs';
2
- import 'react';
@@ -1,4 +0,0 @@
1
- import ShogiPlayer from "./shogi-player.mjs";
2
- export {
3
- ShogiPlayer
4
- };