@mirasen/chessboard 0.1.0 → 1.0.0-rc.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.
Files changed (268) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +224 -47
  3. package/dist/animation/planner.d.ts +11 -6
  4. package/dist/animation/planner.js +167 -48
  5. package/dist/animation/render/fade.d.ts +5 -5
  6. package/dist/animation/render/fade.js +4 -4
  7. package/dist/animation/render/move.d.ts +6 -6
  8. package/dist/animation/render/move.js +6 -6
  9. package/dist/animation/render/plan.d.ts +6 -6
  10. package/dist/animation/render/plan.js +3 -3
  11. package/dist/animation/render/static.d.ts +5 -5
  12. package/dist/animation/render/static.js +4 -4
  13. package/dist/animation/render/types.d.ts +1 -1
  14. package/dist/animation/types.d.ts +15 -16
  15. package/dist/animation/types.js +1 -6
  16. package/dist/extensions/animation/factory.d.ts +1 -1
  17. package/dist/extensions/animation/factory.js +1 -1
  18. package/dist/extensions/animation/types.d.ts +1 -1
  19. package/dist/extensions/factory/main.d.ts +1 -1
  20. package/dist/extensions/factory/main.js +27 -6
  21. package/dist/extensions/factory/runtime.d.ts +6 -5
  22. package/dist/extensions/factory/runtime.js +48 -4
  23. package/dist/extensions/first-party/active-target/factory.d.ts +1 -1
  24. package/dist/extensions/first-party/active-target/factory.js +9 -9
  25. package/dist/extensions/first-party/active-target/types.d.ts +2 -2
  26. package/dist/extensions/first-party/auto-promote/factory.d.ts +2 -0
  27. package/dist/extensions/first-party/auto-promote/factory.js +51 -0
  28. package/dist/extensions/first-party/auto-promote/types.d.ts +14 -0
  29. package/dist/extensions/first-party/auto-promote/types.js +2 -0
  30. package/dist/extensions/first-party/board-events/factory.d.ts +1 -1
  31. package/dist/extensions/first-party/board-events/factory.js +3 -16
  32. package/dist/extensions/first-party/board-events/types.d.ts +6 -7
  33. package/dist/extensions/first-party/common/helpers.d.ts +2 -2
  34. package/dist/extensions/first-party/common/helpers.js +1 -1
  35. package/dist/extensions/first-party/common/types.d.ts +1 -1
  36. package/dist/extensions/first-party/last-move/factory.d.ts +1 -1
  37. package/dist/extensions/first-party/last-move/factory.js +10 -10
  38. package/dist/extensions/first-party/last-move/types.d.ts +2 -2
  39. package/dist/extensions/first-party/legal-moves/factory.d.ts +1 -1
  40. package/dist/extensions/first-party/legal-moves/factory.js +7 -7
  41. package/dist/extensions/first-party/legal-moves/types.d.ts +2 -2
  42. package/dist/extensions/first-party/main-renderer/animation/factory.d.ts +3 -3
  43. package/dist/extensions/first-party/main-renderer/animation/factory.js +3 -3
  44. package/dist/extensions/first-party/main-renderer/animation/render.d.ts +3 -3
  45. package/dist/extensions/first-party/main-renderer/animation/render.js +2 -3
  46. package/dist/extensions/first-party/main-renderer/animation/types.d.ts +7 -7
  47. package/dist/extensions/first-party/main-renderer/animation/update.d.ts +2 -2
  48. package/dist/extensions/first-party/main-renderer/animation/update.js +12 -26
  49. package/dist/extensions/first-party/main-renderer/board/factory.d.ts +2 -2
  50. package/dist/extensions/first-party/main-renderer/board/factory.js +2 -2
  51. package/dist/extensions/first-party/main-renderer/board/render.d.ts +2 -2
  52. package/dist/extensions/first-party/main-renderer/board/render.js +6 -6
  53. package/dist/extensions/first-party/main-renderer/board/types.d.ts +3 -3
  54. package/dist/extensions/first-party/main-renderer/board/update.d.ts +2 -2
  55. package/dist/extensions/first-party/main-renderer/board/update.js +8 -6
  56. package/dist/extensions/first-party/main-renderer/coordinates/factory.d.ts +2 -2
  57. package/dist/extensions/first-party/main-renderer/coordinates/factory.js +1 -1
  58. package/dist/extensions/first-party/main-renderer/coordinates/render.d.ts +2 -2
  59. package/dist/extensions/first-party/main-renderer/coordinates/render.js +7 -7
  60. package/dist/extensions/first-party/main-renderer/coordinates/types.d.ts +2 -2
  61. package/dist/extensions/first-party/main-renderer/drag/factory.d.ts +3 -3
  62. package/dist/extensions/first-party/main-renderer/drag/factory.js +2 -2
  63. package/dist/extensions/first-party/main-renderer/drag/render.d.ts +2 -2
  64. package/dist/extensions/first-party/main-renderer/drag/render.js +2 -2
  65. package/dist/extensions/first-party/main-renderer/drag/types.d.ts +4 -4
  66. package/dist/extensions/first-party/main-renderer/drag/update.d.ts +2 -2
  67. package/dist/extensions/first-party/main-renderer/drag/update.js +1 -1
  68. package/dist/extensions/first-party/main-renderer/factory.d.ts +1 -1
  69. package/dist/extensions/first-party/main-renderer/factory.js +9 -9
  70. package/dist/extensions/first-party/main-renderer/normalize.d.ts +2 -3
  71. package/dist/extensions/first-party/main-renderer/normalize.js +4 -4
  72. package/dist/extensions/first-party/main-renderer/pieces/factory.d.ts +2 -2
  73. package/dist/extensions/first-party/main-renderer/pieces/factory.js +2 -2
  74. package/dist/extensions/first-party/main-renderer/pieces/render.d.ts +2 -2
  75. package/dist/extensions/first-party/main-renderer/pieces/render.js +9 -9
  76. package/dist/extensions/first-party/main-renderer/pieces/suppress.d.ts +4 -4
  77. package/dist/extensions/first-party/main-renderer/pieces/suppress.js +7 -2
  78. package/dist/extensions/first-party/main-renderer/pieces/types.d.ts +5 -5
  79. package/dist/extensions/first-party/main-renderer/pieces/update.d.ts +4 -4
  80. package/dist/extensions/first-party/main-renderer/pieces/update.js +5 -5
  81. package/dist/extensions/first-party/main-renderer/types/extension.d.ts +3 -3
  82. package/dist/extensions/first-party/main-renderer/types/extension.js +1 -1
  83. package/dist/extensions/first-party/main-renderer/types/input.d.ts +2 -2
  84. package/dist/extensions/first-party/main-renderer/types/instance.d.ts +8 -8
  85. package/dist/extensions/first-party/main-renderer/types/internal.d.ts +2 -2
  86. package/dist/extensions/first-party/main-renderer/types/template.d.ts +1 -1
  87. package/dist/extensions/first-party/promotion/factory.d.ts +3 -0
  88. package/dist/extensions/first-party/promotion/factory.js +219 -0
  89. package/dist/extensions/first-party/promotion/normalize.d.ts +3 -0
  90. package/dist/extensions/first-party/promotion/normalize.js +37 -0
  91. package/dist/extensions/first-party/promotion/types/input.d.ts +10 -0
  92. package/dist/extensions/first-party/promotion/types/internal.d.ts +12 -0
  93. package/dist/extensions/first-party/promotion/types/internal.js +22 -0
  94. package/dist/extensions/first-party/promotion/types/main.d.ts +24 -0
  95. package/dist/extensions/first-party/promotion/types/main.js +2 -0
  96. package/dist/extensions/first-party/selected-square/factory.d.ts +1 -1
  97. package/dist/extensions/first-party/selected-square/factory.js +7 -7
  98. package/dist/extensions/first-party/selected-square/types.d.ts +2 -2
  99. package/dist/extensions/index.d.ts +8 -8
  100. package/dist/extensions/index.js +6 -6
  101. package/dist/extensions/invalidation/factory.d.ts +1 -1
  102. package/dist/extensions/types/basic/events.d.ts +10 -33
  103. package/dist/extensions/types/basic/events.js +9 -5
  104. package/dist/extensions/types/basic/interaction.d.ts +21 -0
  105. package/dist/extensions/types/basic/render.d.ts +2 -2
  106. package/dist/extensions/types/basic/transient-visuals.d.ts +3 -2
  107. package/dist/extensions/types/basic/update.d.ts +3 -3
  108. package/dist/extensions/types/context/animation.d.ts +3 -3
  109. package/dist/extensions/types/context/events.d.ts +5 -0
  110. package/dist/extensions/types/context/events.js +1 -0
  111. package/dist/extensions/types/context/render.d.ts +2 -2
  112. package/dist/extensions/types/context/transient-visuals.d.ts +2 -2
  113. package/dist/extensions/types/context/ui-move.d.ts +3 -15
  114. package/dist/extensions/types/context/update.d.ts +4 -4
  115. package/dist/extensions/types/context/update.js +1 -1
  116. package/dist/extensions/types/extension.d.ts +16 -14
  117. package/dist/extensions/types/main.d.ts +16 -11
  118. package/dist/extensions/types/surface/commands.d.ts +14 -5
  119. package/dist/extensions/types/surface/events.d.ts +2 -3
  120. package/dist/extensions/types/surface/main.d.ts +4 -4
  121. package/dist/extensions/types/wrapper.d.ts +23 -22
  122. package/dist/extensions/types/wrapper.js +34 -6
  123. package/dist/extensions/update.d.ts +3 -3
  124. package/dist/extensions/update.js +2 -2
  125. package/dist/index.d.ts +4 -4
  126. package/dist/index.js +1 -1
  127. package/dist/layout/factory.d.ts +1 -1
  128. package/dist/layout/factory.js +4 -4
  129. package/dist/layout/geometry/factory.d.ts +3 -12
  130. package/dist/layout/geometry/factory.js +17 -18
  131. package/dist/layout/geometry/helpers.d.ts +5 -0
  132. package/dist/layout/geometry/helpers.js +33 -0
  133. package/dist/layout/geometry/types.d.ts +14 -13
  134. package/dist/layout/helpers.d.ts +3 -4
  135. package/dist/layout/helpers.js +5 -5
  136. package/dist/layout/mutation.d.ts +1 -1
  137. package/dist/layout/reducers.d.ts +1 -1
  138. package/dist/layout/reducers.js +10 -9
  139. package/dist/layout/types.d.ts +7 -7
  140. package/dist/mutation/pipeline.d.ts +1 -1
  141. package/dist/mutation/pipeline.js +1 -1
  142. package/dist/mutation/session.d.ts +1 -1
  143. package/dist/render/factory.d.ts +1 -1
  144. package/dist/render/factory.js +7 -7
  145. package/dist/render/mount.d.ts +1 -1
  146. package/dist/render/mount.js +4 -4
  147. package/dist/render/rendering/animation.d.ts +1 -1
  148. package/dist/render/rendering/animation.js +1 -1
  149. package/dist/render/rendering/helpers.d.ts +1 -1
  150. package/dist/render/rendering/state.d.ts +2 -2
  151. package/dist/render/rendering/state.js +9 -9
  152. package/dist/render/rendering/visuals.d.ts +2 -2
  153. package/dist/render/rendering/visuals.js +1 -1
  154. package/dist/render/scheduler/scheduler.d.ts +1 -1
  155. package/dist/render/svg/factory.d.ts +2 -2
  156. package/dist/render/svg/factory.js +1 -1
  157. package/dist/render/svg/helpers.d.ts +1 -1
  158. package/dist/render/svg/helpers.js +1 -1
  159. package/dist/render/types.d.ts +5 -5
  160. package/dist/runtime/factory/events.d.ts +3 -0
  161. package/dist/runtime/factory/events.js +18 -0
  162. package/dist/runtime/factory/helpers.d.ts +2 -2
  163. package/dist/runtime/factory/helpers.js +14 -14
  164. package/dist/runtime/factory/input.d.ts +2 -2
  165. package/dist/runtime/factory/input.js +20 -13
  166. package/dist/runtime/factory/main.d.ts +1 -1
  167. package/dist/runtime/factory/main.js +56 -16
  168. package/dist/runtime/input/adapter/event.d.ts +3 -0
  169. package/dist/runtime/input/adapter/event.js +19 -0
  170. package/dist/runtime/input/adapter/factory.d.ts +1 -1
  171. package/dist/runtime/input/adapter/factory.js +19 -38
  172. package/dist/runtime/input/adapter/helpers.d.ts +3 -5
  173. package/dist/runtime/input/adapter/helpers.js +60 -12
  174. package/dist/runtime/input/adapter/pointer.d.ts +7 -11
  175. package/dist/runtime/input/adapter/pointer.js +37 -70
  176. package/dist/runtime/input/adapter/types.d.ts +7 -4
  177. package/dist/runtime/input/adapter/types.js +6 -1
  178. package/dist/runtime/input/controller/factory.d.ts +1 -1
  179. package/dist/runtime/input/controller/factory.js +13 -12
  180. package/dist/runtime/input/controller/helpers.d.ts +2 -2
  181. package/dist/runtime/input/controller/pointer.d.ts +6 -7
  182. package/dist/runtime/input/controller/pointer.js +39 -38
  183. package/dist/runtime/input/controller/transient-visuals.d.ts +3 -3
  184. package/dist/runtime/input/controller/transient-visuals.js +12 -5
  185. package/dist/runtime/input/controller/types.d.ts +8 -7
  186. package/dist/runtime/layout.d.ts +1 -1
  187. package/dist/runtime/layout.js +2 -2
  188. package/dist/runtime/lifecycle.d.ts +2 -2
  189. package/dist/runtime/lifecycle.js +8 -8
  190. package/dist/runtime/mutation/extension-update.d.ts +1 -1
  191. package/dist/runtime/mutation/factory.d.ts +1 -1
  192. package/dist/runtime/mutation/factory.js +6 -6
  193. package/dist/runtime/mutation/interaction.d.ts +1 -1
  194. package/dist/runtime/mutation/interaction.js +3 -7
  195. package/dist/runtime/mutation/invalidation.d.ts +1 -0
  196. package/dist/runtime/mutation/invalidation.js +1 -1
  197. package/dist/runtime/mutation/last-move.d.ts +1 -1
  198. package/dist/runtime/mutation/layout.d.ts +1 -1
  199. package/dist/runtime/mutation/pipeline.d.ts +6 -6
  200. package/dist/runtime/mutation/request-render.d.ts +1 -1
  201. package/dist/runtime/mutation/request-render.js +1 -1
  202. package/dist/runtime/mutation/run.d.ts +1 -1
  203. package/dist/runtime/mutation/types.d.ts +10 -8
  204. package/dist/runtime/types/main.d.ts +8 -6
  205. package/dist/state/board/check.d.ts +3 -3
  206. package/dist/state/board/check.js +1 -1
  207. package/dist/state/board/coords.d.ts +1 -1
  208. package/dist/state/board/denormalize.d.ts +3 -3
  209. package/dist/state/board/denormalize.js +4 -4
  210. package/dist/state/board/factory.d.ts +2 -2
  211. package/dist/state/board/factory.js +4 -4
  212. package/dist/state/board/mutation.d.ts +2 -2
  213. package/dist/state/board/normalize.d.ts +2 -2
  214. package/dist/state/board/normalize.js +2 -2
  215. package/dist/state/board/piece.d.ts +1 -1
  216. package/dist/state/board/position.d.ts +2 -2
  217. package/dist/state/board/position.js +2 -2
  218. package/dist/state/board/reducers.d.ts +2 -2
  219. package/dist/state/board/reducers.js +3 -3
  220. package/dist/state/board/types/input.d.ts +1 -1
  221. package/dist/state/board/types/internal.d.ts +1 -1
  222. package/dist/state/board/types/main.d.ts +3 -3
  223. package/dist/state/board/types/output.d.ts +2 -2
  224. package/dist/state/change/{factory.d.ts → factory/main.d.ts} +1 -1
  225. package/dist/state/change/{factory.js → factory/main.js} +8 -5
  226. package/dist/state/change/factory/ui-move.d.ts +4 -0
  227. package/dist/{runtime → state/change}/factory/ui-move.js +9 -9
  228. package/dist/state/change/helpers.d.ts +6 -4
  229. package/dist/state/change/helpers.js +12 -2
  230. package/dist/state/change/mutation.d.ts +2 -2
  231. package/dist/state/change/reducers.d.ts +4 -4
  232. package/dist/state/change/reducers.js +4 -4
  233. package/dist/state/change/types/main.d.ts +18 -0
  234. package/dist/state/change/types/main.js +1 -0
  235. package/dist/state/change/types/ui-move.d.ts +25 -0
  236. package/dist/state/change/types/ui-move.js +1 -0
  237. package/dist/state/factory.d.ts +1 -1
  238. package/dist/state/factory.js +4 -4
  239. package/dist/state/interaction/factory.d.ts +1 -1
  240. package/dist/state/interaction/factory.js +7 -5
  241. package/dist/state/interaction/helpers.d.ts +4 -2
  242. package/dist/state/interaction/helpers.js +5 -2
  243. package/dist/state/interaction/movability.d.ts +3 -3
  244. package/dist/state/interaction/movability.js +2 -2
  245. package/dist/state/interaction/mutation.d.ts +1 -1
  246. package/dist/state/interaction/normalize.d.ts +2 -2
  247. package/dist/state/interaction/normalize.js +2 -2
  248. package/dist/state/interaction/reducers.d.ts +3 -3
  249. package/dist/state/interaction/reducers.js +3 -3
  250. package/dist/state/interaction/types/input.d.ts +1 -1
  251. package/dist/state/interaction/types/internal.d.ts +10 -2
  252. package/dist/state/interaction/types/main.d.ts +4 -4
  253. package/dist/state/types.d.ts +6 -6
  254. package/dist/state/view/factory.d.ts +1 -1
  255. package/dist/state/view/factory.js +2 -2
  256. package/dist/state/view/mutation.d.ts +1 -1
  257. package/dist/state/view/reducers.d.ts +2 -2
  258. package/dist/state/view/types/internal.d.ts +1 -1
  259. package/dist/state/view/types/main.d.ts +4 -4
  260. package/dist/wrapper/factory.d.ts +2 -2
  261. package/dist/wrapper/factory.js +3 -27
  262. package/dist/wrapper/types.d.ts +4 -4
  263. package/package.json +9 -5
  264. package/dist/runtime/factory/ui-move.d.ts +0 -4
  265. package/dist/runtime/types/ui-move.d.ts +0 -9
  266. package/dist/state/change/types.d.ts +0 -17
  267. /package/dist/{runtime/types/ui-move.js → extensions/first-party/promotion/types/input.js} +0 -0
  268. /package/dist/{state/change/types.js → extensions/types/basic/interaction.js} +0 -0
@@ -1,6 +1,6 @@
1
- import { ExtensionInvalidationState } from '../../invalidation/types';
2
- import { ExtensionAnimationSession } from '../basic/animation';
3
- import { ExtensionRenderContext } from './render';
1
+ import { ExtensionInvalidationState } from '../../invalidation/types.js';
2
+ import { ExtensionAnimationSession } from '../basic/animation.js';
3
+ import { ExtensionRenderContext } from './render.js';
4
4
  export interface ExtensionSubmittedAnimationSession extends ExtensionAnimationSession {
5
5
  readonly status: 'submitted';
6
6
  }
@@ -0,0 +1,5 @@
1
+ import { SceneEvent } from '../basic/events.js';
2
+ export interface ExtensionOnEventContext {
3
+ rawEvent: Event;
4
+ sceneEvent: SceneEvent | null;
5
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,5 +1,5 @@
1
- import { ExtensionReadonlyInvalidationState } from '../../invalidation/types';
2
- import { RenderFrameSnapshot } from '../basic/render';
1
+ import { ExtensionReadonlyInvalidationState } from '../../invalidation/types.js';
2
+ import { RenderFrameSnapshot } from '../basic/render.js';
3
3
  export interface ExtensionRenderContext {
4
4
  readonly currentFrame: RenderFrameSnapshot;
5
5
  readonly invalidation: ExtensionReadonlyInvalidationState;
@@ -1,6 +1,6 @@
1
1
  import { ReadonlyDeep } from 'type-fest';
2
- import { RenderFrameSnapshot } from '../basic/render';
3
- import { TransientInput } from '../basic/transient-visuals';
2
+ import { RenderFrameSnapshot } from '../basic/render.js';
3
+ import { TransientInput } from '../basic/transient-visuals.js';
4
4
  export interface ExtensionRenderTransientVisualsContext {
5
5
  readonly currentFrame: RenderFrameSnapshot;
6
6
  readonly transientInput: ReadonlyDeep<TransientInput>;
@@ -1,16 +1,4 @@
1
- import { MoveRequest, Square } from '../../../state/board/types/internal';
2
- import { MoveDestinationSnapshot } from '../../../state/interaction/types/internal';
3
- export type ExtensionUIMoveRequestStatus = 'unresolved' | 'deferred' | 'resolved';
4
- export interface ExtensionUIMoveRequestContextSnapshot {
5
- readonly status: ExtensionUIMoveRequestStatus;
6
- readonly sourceSquare: Square;
7
- readonly destination: MoveDestinationSnapshot;
8
- readonly canBeAutoResolved: boolean;
9
- readonly resolvedMoveRequest: MoveRequest | null;
10
- }
11
- export interface ExtensionUIMoveRequestContext extends ExtensionUIMoveRequestContextSnapshot {
12
- defer(): void;
13
- resolve(request: MoveRequest): void;
14
- autoresolve(): void;
15
- getSnapshot(): ExtensionUIMoveRequestContextSnapshot;
1
+ import { PendingUIMoveRequest } from '../../../state/change/types/ui-move.js';
2
+ export interface ExtensionPendingUIMoveRequestContext {
3
+ readonly request: PendingUIMoveRequest;
16
4
  }
@@ -1,7 +1,7 @@
1
- import { RuntimeReadonlyMutationSession } from '../../../runtime/mutation/types';
2
- import { ExtensionInvalidationState } from '../../invalidation/types';
3
- import { RenderFrameSnapshot } from '../basic/render';
4
- import { UpdateFrameSnapshot, UpdateFrameSnapshotMounted, UpdateFrameSnapshotUnmounted } from '../basic/update';
1
+ import { RuntimeReadonlyMutationSession } from '../../../runtime/mutation/types.js';
2
+ import { ExtensionInvalidationState } from '../../invalidation/types.js';
3
+ import { RenderFrameSnapshot } from '../basic/render.js';
4
+ import { UpdateFrameSnapshot, UpdateFrameSnapshotMounted, UpdateFrameSnapshotUnmounted } from '../basic/update.js';
5
5
  export interface ExtensionUpdateContextCommon {
6
6
  readonly previousFrame: UpdateFrameSnapshot | null;
7
7
  readonly mutation: RuntimeReadonlyMutationSession;
@@ -1,4 +1,4 @@
1
- import { isFrameMounted, isFrameRenderable } from '../basic/update';
1
+ import { isFrameMounted, isFrameRenderable } from '../basic/update.js';
2
2
  export function isUpdateContextCommonMounted(context) {
3
3
  return isFrameMounted(context.currentFrame);
4
4
  }
@@ -1,25 +1,27 @@
1
- import { SceneEvent } from './basic/events';
2
- import { ExtensionInstanceMountOptions, ExtensionSlotName } from './basic/mount';
3
- import { ExtensionAnimationFinishedContext, ExtensionCleanAnimationContext, ExtensionPrepareAnimationContext, ExtensionRenderAnimationContext } from './context/animation';
4
- import { ExtensionRenderContext } from './context/render';
5
- import { ExtensionRenderTransientVisualsContext } from './context/transient-visuals';
6
- import { ExtensionUIMoveRequestContext } from './context/ui-move';
7
- import { ExtensionUpdateContext } from './context/update';
8
- import { ExtensionRuntimeSurface } from './surface/main';
1
+ import { ExtensionDragSessionSnapshot } from './basic/interaction.js';
2
+ import { ExtensionInstanceMountOptions, ExtensionSlotName } from './basic/mount.js';
3
+ import { ExtensionAnimationFinishedContext, ExtensionCleanAnimationContext, ExtensionPrepareAnimationContext, ExtensionRenderAnimationContext } from './context/animation.js';
4
+ import { ExtensionOnEventContext } from './context/events.js';
5
+ import { ExtensionRenderContext } from './context/render.js';
6
+ import { ExtensionRenderTransientVisualsContext } from './context/transient-visuals.js';
7
+ import { ExtensionPendingUIMoveRequestContext } from './context/ui-move.js';
8
+ import { ExtensionUpdateContext } from './context/update.js';
9
+ import { ExtensionRuntimeSurface } from './surface/main.js';
9
10
  interface ExtensionInstanceBase<TId extends string, TSlots extends readonly ExtensionSlotName[]> {
10
11
  readonly id: TId;
11
- mount(env: ExtensionInstanceMountOptions<TSlots>): void;
12
- unmount(): void;
13
- destroy(): void;
14
- onUpdate(context: ExtensionUpdateContext): void;
15
- onUIMoveRequest?(context: ExtensionUIMoveRequestContext): void;
12
+ mount?(env: ExtensionInstanceMountOptions<TSlots>): void;
13
+ unmount?(): void;
14
+ destroy?(): void;
15
+ onUpdate?(context: ExtensionUpdateContext): void;
16
16
  render?(context: ExtensionRenderContext): void;
17
17
  prepareAnimation?(context: ExtensionPrepareAnimationContext): void;
18
18
  renderAnimation?(context: ExtensionRenderAnimationContext): void;
19
19
  onAnimationFinished?(context: ExtensionAnimationFinishedContext): void;
20
20
  cleanAnimation?(context: ExtensionCleanAnimationContext): void;
21
+ completeDrag?(session: ExtensionDragSessionSnapshot): void;
21
22
  renderTransientVisuals?(context: ExtensionRenderTransientVisualsContext): void;
22
- onEvent?(event: SceneEvent): void;
23
+ onUIMoveRequest?(context: ExtensionPendingUIMoveRequestContext): void;
24
+ onEvent?(context: ExtensionOnEventContext): void;
23
25
  }
24
26
  type ExtensionInstancePublicPart<TPublic> = [TPublic] extends [never] ? Record<never, never> : {
25
27
  getPublic(): TPublic;
@@ -1,11 +1,13 @@
1
- import { RuntimeReadonlyMutationSession } from '../../runtime/mutation/types';
2
- import { ExtensionInvalidationState } from '../invalidation/types';
3
- import { ExtensionAnimationControllerInternalSurface } from './basic/animation';
4
- import { SceneEventType } from './basic/events';
5
- import { UpdateFrameSnapshot } from './basic/update';
6
- import { ExtensionUIMoveRequestContext } from './context/ui-move';
7
- import { AnyExtensionDefinition, AnyExtensionInstance } from './extension';
8
- import { ExtensionRuntimeSurfaceCommands } from './surface/commands';
1
+ import { RuntimeReadonlyMutationSession } from '../../runtime/mutation/types.js';
2
+ import { DragSessionExtensionOwned } from '../../state/interaction/types/internal.js';
3
+ import { ExtensionInvalidationState } from '../invalidation/types.js';
4
+ import { ExtensionAnimationControllerInternalSurface } from './basic/animation.js';
5
+ import { UpdateFrameSnapshot } from './basic/update.js';
6
+ import { ExtensionOnEventContext } from './context/events.js';
7
+ import { ExtensionPendingUIMoveRequestContext } from './context/ui-move.js';
8
+ import { AnyExtensionDefinition, AnyExtensionInstance } from './extension.js';
9
+ import { ExtensionRuntimeSurfaceCommandsInternalSurface } from './surface/commands.js';
10
+ import { ExtensionRuntimeSurfaceEvents } from './surface/events.js';
9
11
  export interface ExtensionSystemExtensionRecord {
10
12
  readonly id: string;
11
13
  readonly definition: AnyExtensionDefinition;
@@ -14,13 +16,14 @@ export interface ExtensionSystemExtensionRecord {
14
16
  readonly animation: ExtensionAnimationControllerInternalSurface;
15
17
  }
16
18
  export interface ExtensionSystemInitOptions {
17
- extensionRuntimeSurfaceCommands: ExtensionRuntimeSurfaceCommands;
19
+ extensionRuntimeSurfaceCommands: ExtensionRuntimeSurfaceCommandsInternalSurface;
20
+ extensionRuntimeSurfaceEvents: ExtensionRuntimeSurfaceEvents;
18
21
  extensions?: readonly AnyExtensionDefinition[];
19
22
  }
20
23
  export interface ExtensionSystemInternal {
21
24
  readonly extensions: Map<string, ExtensionSystemExtensionRecord>;
22
25
  readonly transientVisualsSubscribers: Set<string>;
23
- readonly eventSubscribers: Map<string, Set<SceneEventType>>;
26
+ readonly eventSubscribers: Map<string, Set<string>>;
24
27
  currentFrame: UpdateFrameSnapshot | null;
25
28
  }
26
29
  export interface ExtensionSystemUpdateRequest {
@@ -37,7 +40,9 @@ export interface ExtensionSystem {
37
40
  getPublicRecord(): Readonly<Record<string, unknown>>;
38
41
  getSharedDataForRenderSystem(): ExtensionSystemSharedDataForRenderSystem;
39
42
  onUpdate(request: ExtensionSystemUpdateRequest): void;
40
- onUIMoveRequest(context: ExtensionUIMoveRequestContext): void;
43
+ onUIMoveRequest(context: ExtensionPendingUIMoveRequestContext): void;
44
+ onEvent(context: ExtensionOnEventContext): void;
45
+ completeDrag(session: DragSessionExtensionOwned): void;
41
46
  onUnmount(): void;
42
47
  onDestroy(): void;
43
48
  }
@@ -1,8 +1,11 @@
1
- import { LayoutSnapshot } from '../../../layout/types';
2
- import { ColorInput, MoveRequestInput, PiecePositionInput, PositionInput, SquareString } from '../../../state/board/types/input';
3
- import { Move } from '../../../state/board/types/internal';
4
- import { MovabilityInput } from '../../../state/interaction/types/input';
5
- import { RuntimeStateSnapshot } from '../../../state/types';
1
+ import { LayoutSnapshot } from '../../../layout/types.js';
2
+ import { ColorInput, MoveRequestInput, PiecePositionInput, PositionInput, SquareString } from '../../../state/board/types/input.js';
3
+ import { Move } from '../../../state/board/types/internal.js';
4
+ import { DeferredUIMoveResolutionDetails } from '../../../state/change/types/ui-move.js';
5
+ import { MovabilityInput } from '../../../state/interaction/types/input.js';
6
+ import { DragSessionExtensionOwned } from '../../../state/interaction/types/internal.js';
7
+ import { RuntimeStateSnapshot } from '../../../state/types.js';
8
+ import { ExtensionDragSession } from '../basic/interaction.js';
6
9
  export interface ExtensionRuntimeSurfaceCommandsSnapshot {
7
10
  readonly state: RuntimeStateSnapshot;
8
11
  readonly layout: LayoutSnapshot;
@@ -19,8 +22,14 @@ export interface ExtensionRuntimeSurfaceCommands {
19
22
  setOrientation(orientation: ColorInput): boolean;
20
23
  setMovability(movability: MovabilityInput): boolean;
21
24
  select(square: SquareString | null): boolean;
25
+ startDrag(session: ExtensionDragSession): boolean;
22
26
  clearActiveInteraction(): boolean;
23
27
  clearInteraction(): boolean;
28
+ resolveDeferredUIMoveRequest(details: DeferredUIMoveResolutionDetails): Move;
29
+ cancelDeferredUIMoveRequest(): boolean;
24
30
  requestRender(request: ExtensionRuntimeSurfaceCommandsRenderRequest): void;
25
31
  getSnapshot(): ExtensionRuntimeSurfaceCommandsSnapshot;
26
32
  }
33
+ export interface ExtensionRuntimeSurfaceCommandsInternalSurface extends ExtensionRuntimeSurfaceCommands {
34
+ startDrag(session: DragSessionExtensionOwned): boolean;
35
+ }
@@ -1,5 +1,4 @@
1
- import { SceneEventType } from '../basic/events';
2
1
  export interface ExtensionRuntimeSurfaceEvents {
3
- subscribe(events: Iterable<SceneEventType>): void;
4
- unsubscribe(events?: Iterable<SceneEventType>): void;
2
+ subscribeEvent<K extends keyof HTMLElementEventMap>(type: K): void;
3
+ unsubscribeEvent<K extends keyof HTMLElementEventMap>(type: K): void;
5
4
  }
@@ -1,7 +1,7 @@
1
- import { ExtensionAnimationController } from '../basic/animation';
2
- import { ExtensionRuntimeSurfaceCommands } from './commands';
3
- import { ExtensionRuntimeSurfaceEvents } from './events';
4
- import { ExtensionRuntimeSurfaceTransientVisuals } from './transient-visuals';
1
+ import { ExtensionAnimationController } from '../basic/animation.js';
2
+ import { ExtensionRuntimeSurfaceCommands } from './commands.js';
3
+ import { ExtensionRuntimeSurfaceEvents } from './events.js';
4
+ import { ExtensionRuntimeSurfaceTransientVisuals } from './transient-visuals.js';
5
5
  export interface ExtensionRuntimeSurface {
6
6
  readonly commands: ExtensionRuntimeSurfaceCommands;
7
7
  readonly animation: ExtensionAnimationController;
@@ -1,26 +1,27 @@
1
1
  /**
2
2
  * Public built-in extension ids accepted by createBoard({ extensions })
3
3
  */
4
- import { ActiveTargetDefinition } from '../first-party/active-target/types';
5
- import { BoardEventsDefinition } from '../first-party/board-events/types';
6
- import { LastMoveDefinition } from '../first-party/last-move/types';
7
- import { LegalMovesDefinition } from '../first-party/legal-moves/types';
8
- import { MainRendererDefinition } from '../first-party/main-renderer/types/extension';
9
- import { SelectedSquareDefinition } from '../first-party/selected-square/types';
10
- export declare const DefaultBuiltinChessboardExtensions: readonly ["mainRenderer", "events", "selectedSquare", "activeTarget", "legalMoves", "lastMove"];
11
- export type BuiltInExtensionId = (typeof DefaultBuiltinChessboardExtensions)[number];
12
- /**
13
- * Default built-in extensions used when createBoard(...) receives no extensions option
14
- */
4
+ import { createActiveTarget } from '../first-party/active-target/factory.js';
5
+ import { createAutoPromote } from '../first-party/auto-promote/factory.js';
6
+ import { createBoardEvents } from '../first-party/board-events/factory.js';
7
+ import { createLastMove } from '../first-party/last-move/factory.js';
8
+ import { createLegalMoves } from '../first-party/legal-moves/factory.js';
9
+ import { createMainRenderer } from '../first-party/main-renderer/factory.js';
10
+ import { createPromotion } from '../first-party/promotion/factory.js';
11
+ import { createSelectedSquare } from '../first-party/selected-square/factory.js';
12
+ export declare const builtInExtensionFactoryMap: {
13
+ renderer: typeof createMainRenderer;
14
+ selectedSquare: typeof createSelectedSquare;
15
+ lastMove: typeof createLastMove;
16
+ activeTarget: typeof createActiveTarget;
17
+ legalMoves: typeof createLegalMoves;
18
+ events: typeof createBoardEvents;
19
+ autoPromote: typeof createAutoPromote;
20
+ promotion: typeof createPromotion;
21
+ };
22
+ export type BuiltInExtensionId = keyof typeof builtInExtensionFactoryMap;
23
+ export type BuiltInExtensionDefinitionMap = {
24
+ [Id in BuiltInExtensionId]: ReturnType<(typeof builtInExtensionFactoryMap)[Id]>;
25
+ };
26
+ export declare const DefaultBuiltinChessboardExtensions: readonly ["renderer", "selectedSquare", "lastMove", "activeTarget", "legalMoves", "events", "autoPromote", "promotion"];
15
27
  export type DefaultBuiltinChessboardExtensions = typeof DefaultBuiltinChessboardExtensions;
16
- /**
17
- * Map built-in public ids -> concrete extension definition types
18
- */
19
- export interface BuiltInExtensionDefinitionMap {
20
- mainRenderer: MainRendererDefinition;
21
- events: BoardEventsDefinition;
22
- selectedSquare: SelectedSquareDefinition;
23
- activeTarget: ActiveTargetDefinition;
24
- legalMoves: LegalMovesDefinition;
25
- lastMove: LastMoveDefinition;
26
- }
@@ -1,11 +1,39 @@
1
1
  /**
2
2
  * Public built-in extension ids accepted by createBoard({ extensions })
3
3
  */
4
+ import { createActiveTarget } from '../first-party/active-target/factory.js';
5
+ import { EXTENSION_ID as EXTENSION_ID_ACTIVE_TARGET } from '../first-party/active-target/types.js';
6
+ import { createAutoPromote } from '../first-party/auto-promote/factory.js';
7
+ import { EXTENSION_ID as EXTENSION_ID_AUTO_PROMOTE } from '../first-party/auto-promote/types.js';
8
+ import { createBoardEvents } from '../first-party/board-events/factory.js';
9
+ import { EXTENSION_ID as EXTENSION_ID_BOARD_EVENTS } from '../first-party/board-events/types.js';
10
+ import { createLastMove } from '../first-party/last-move/factory.js';
11
+ import { EXTENSION_ID as EXTENSION_ID_LAST_MOVE } from '../first-party/last-move/types.js';
12
+ import { createLegalMoves } from '../first-party/legal-moves/factory.js';
13
+ import { EXTENSION_ID as EXTENSION_ID_LEGAL_MOVES } from '../first-party/legal-moves/types.js';
14
+ import { createMainRenderer } from '../first-party/main-renderer/factory.js';
15
+ import { EXTENSION_ID as EXTENSION_ID_RENDERER } from '../first-party/main-renderer/types/extension.js';
16
+ import { createPromotion } from '../first-party/promotion/factory.js';
17
+ import { EXTENSION_ID as EXTENSION_ID_PROMOTION } from '../first-party/promotion/types/main.js';
18
+ import { createSelectedSquare } from '../first-party/selected-square/factory.js';
19
+ import { EXTENSION_ID as EXTENSION_ID_SELECTED_SQUARE } from '../first-party/selected-square/types.js';
20
+ export const builtInExtensionFactoryMap = {
21
+ [EXTENSION_ID_RENDERER]: createMainRenderer,
22
+ [EXTENSION_ID_SELECTED_SQUARE]: createSelectedSquare,
23
+ [EXTENSION_ID_LAST_MOVE]: createLastMove,
24
+ [EXTENSION_ID_ACTIVE_TARGET]: createActiveTarget,
25
+ [EXTENSION_ID_LEGAL_MOVES]: createLegalMoves,
26
+ [EXTENSION_ID_BOARD_EVENTS]: createBoardEvents,
27
+ [EXTENSION_ID_AUTO_PROMOTE]: createAutoPromote,
28
+ [EXTENSION_ID_PROMOTION]: createPromotion
29
+ };
4
30
  export const DefaultBuiltinChessboardExtensions = [
5
- 'mainRenderer',
6
- 'events',
7
- 'selectedSquare',
8
- 'activeTarget',
9
- 'legalMoves',
10
- 'lastMove'
31
+ EXTENSION_ID_RENDERER,
32
+ EXTENSION_ID_SELECTED_SQUARE,
33
+ EXTENSION_ID_LAST_MOVE,
34
+ EXTENSION_ID_ACTIVE_TARGET,
35
+ EXTENSION_ID_LEGAL_MOVES,
36
+ EXTENSION_ID_BOARD_EVENTS,
37
+ EXTENSION_ID_AUTO_PROMOTE,
38
+ EXTENSION_ID_PROMOTION
11
39
  ];
@@ -1,4 +1,4 @@
1
- import { ExtensionUIMoveRequestContext } from './types/context/ui-move';
2
- import { ExtensionSystemInternal, ExtensionSystemUpdateRequest } from './types/main';
1
+ import { ExtensionPendingUIMoveRequestContext } from './types/context/ui-move.js';
2
+ import { ExtensionSystemInternal, ExtensionSystemUpdateRequest } from './types/main.js';
3
3
  export declare function extensionSystemUpdateState(state: ExtensionSystemInternal, request: ExtensionSystemUpdateRequest): void;
4
- export declare function extensionSystemUpdateUIMoveRequest(state: ExtensionSystemInternal, context: ExtensionUIMoveRequestContext): void;
4
+ export declare function extensionSystemUpdateUIMoveRequest(state: ExtensionSystemInternal, context: ExtensionPendingUIMoveRequestContext): void;
@@ -1,4 +1,4 @@
1
- import { isUpdateContextCommonMounted } from './types/context/update';
1
+ import { isUpdateContextCommonMounted } from './types/context/update.js';
2
2
  export function extensionSystemUpdateState(state, request) {
3
3
  // Prepare base context
4
4
  const contextCommon = {
@@ -16,7 +16,7 @@ export function extensionSystemUpdateState(state, request) {
16
16
  : {
17
17
  ...contextCommon
18
18
  };
19
- extension.instance.onUpdate(context);
19
+ extension.instance.onUpdate?.(context);
20
20
  }
21
21
  state.currentFrame = request.state;
22
22
  }
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { createBoard } from './wrapper/factory';
2
- export type { Chessboard, ChessboardExtensionInput, ChessboardInitOptions, ChessboardRuntimeSurface } from './wrapper/types';
3
- export type { MoveRequestInput, PiecePositionRecordString } from './state/board/types/input';
4
- export type { RuntimeStateInitOptions } from './state/types';
1
+ export { createBoard } from './wrapper/factory.js';
2
+ export type { Chessboard, ChessboardExtensionInput, ChessboardInitOptions, ChessboardRuntimeSurface } from './wrapper/types.js';
3
+ export type { MoveRequestInput, PiecePositionRecordString } from './state/board/types/input.js';
4
+ export type { RuntimeStateInitOptions } from './state/types.js';
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export { createBoard } from './wrapper/factory';
1
+ export { createBoard } from './wrapper/factory.js';
@@ -1,2 +1,2 @@
1
- import { Layout } from './types';
1
+ import { Layout } from './types.js';
2
2
  export declare function createLayout(): Layout;
@@ -1,8 +1,8 @@
1
1
  import { cloneDeep } from 'es-toolkit/object';
2
- import { layoutRefreshGeometry } from './reducers';
2
+ import { layoutRefreshGeometry } from './reducers.js';
3
3
  function createLayoutInternal() {
4
4
  return {
5
- boardSize: 0,
5
+ sceneSize: null,
6
6
  orientation: 0 /* ColorCode.White */,
7
7
  geometry: null,
8
8
  layoutEpoch: 0
@@ -11,8 +11,8 @@ function createLayoutInternal() {
11
11
  export function createLayout() {
12
12
  const internalState = createLayoutInternal();
13
13
  return {
14
- get boardSize() {
15
- return internalState.boardSize;
14
+ get sceneSize() {
15
+ return internalState.sceneSize;
16
16
  },
17
17
  get orientation() {
18
18
  return internalState.orientation;
@@ -1,12 +1,3 @@
1
- import { ColorCode } from '../../state/board/types/internal';
2
- import { RenderGeometry } from './types';
3
- /**
4
- * Create RenderGeometry for a given board size (in px) and orientation.
5
- * - Geometry uses an SVG-local coordinate system with origin at top-left.
6
- * - Orientation mapping:
7
- * - 'white': files increase left→right (a..h), ranks increase bottom→top (1..8).
8
- * yIndex = 7 - rank, xIndex = file
9
- * - 'black': files increase right→left (a..h), ranks increase top→bottom (1..8).
10
- * yIndex = rank, xIndex = 7 - file
11
- */
12
- export declare function createRenderGeometry(boardSize: number, orientation: ColorCode): RenderGeometry;
1
+ import { ColorCode } from '../../state/board/types/internal.js';
2
+ import { SceneRenderGeometry, Size } from './types.js';
3
+ export declare function createRenderGeometry(sceneSize: Size, orientation: ColorCode): SceneRenderGeometry;
@@ -1,32 +1,31 @@
1
- import { fileOf, rankOf } from '../../state/board/coords';
2
- /**
3
- * Create RenderGeometry for a given board size (in px) and orientation.
4
- * - Geometry uses an SVG-local coordinate system with origin at top-left.
5
- * - Orientation mapping:
6
- * - 'white': files increase left→right (a..h), ranks increase bottom→top (1..8).
7
- * yIndex = 7 - rank, xIndex = file
8
- * - 'black': files increase right→left (a..h), ranks increase top→bottom (1..8).
9
- * yIndex = rank, xIndex = 7 - file
10
- */
11
- export function createRenderGeometry(boardSize, orientation) {
12
- if (!(boardSize > 0 && Number.isFinite(boardSize))) {
13
- throw new RangeError(`Invalid boardSize: ${boardSize}`);
1
+ import { fileOf, rankOf } from '../../state/board/coords.js';
2
+ import { makeBoardRect, measureBoardSize } from './helpers.js';
3
+ export function createRenderGeometry(sceneSize, orientation) {
4
+ if (!(sceneSize.height > 0 &&
5
+ Number.isFinite(sceneSize.height) &&
6
+ sceneSize.width > 0 &&
7
+ Number.isFinite(sceneSize.width))) {
8
+ throw new RangeError(`Invalid sceneSize: ${JSON.stringify(sceneSize)}`);
14
9
  }
10
+ const boardSize = measureBoardSize(sceneSize);
11
+ const boardRect = makeBoardRect(sceneSize);
15
12
  const squareSize = boardSize / 8;
16
13
  const white = orientation === 0 /* ColorCode.White */;
17
14
  return {
18
- boardSize,
15
+ sceneSize: { ...sceneSize },
16
+ boardRect,
19
17
  squareSize,
20
18
  orientation,
21
- squareRect(sq) {
19
+ getSquareRect(sq) {
22
20
  const f = fileOf(sq);
23
21
  const r = rankOf(sq);
24
22
  const xIndex = white ? f : 7 - f;
25
23
  const yIndex = white ? 7 - r : r;
26
24
  return {
27
- x: xIndex * squareSize,
28
- y: yIndex * squareSize,
29
- size: squareSize
25
+ x: boardRect.x + xIndex * squareSize,
26
+ y: boardRect.y + yIndex * squareSize,
27
+ width: squareSize,
28
+ height: squareSize
30
29
  };
31
30
  }
32
31
  };
@@ -0,0 +1,5 @@
1
+ import { Rect, RectSnapshot, Size, SizeSnapshot } from './types.js';
2
+ export declare function sceneRectsEqual(rect1: RectSnapshot | null, rect2: RectSnapshot | null): boolean;
3
+ export declare function sceneSizesEqual(size1: SizeSnapshot | null, size2: SizeSnapshot | null): boolean;
4
+ export declare function measureBoardSize(sceneSize: Size): number;
5
+ export declare function makeBoardRect(sceneSize: Size): Rect;
@@ -0,0 +1,33 @@
1
+ export function sceneRectsEqual(rect1, rect2) {
2
+ if (rect1 === null && rect2 === null) {
3
+ return true;
4
+ }
5
+ if (rect1 === null || rect2 === null) {
6
+ return false;
7
+ }
8
+ return (rect1.x === rect2.x &&
9
+ rect1.y === rect2.y &&
10
+ rect1.width === rect2.width &&
11
+ rect1.height === rect2.height);
12
+ }
13
+ export function sceneSizesEqual(size1, size2) {
14
+ if (size1 === null && size2 === null) {
15
+ return true;
16
+ }
17
+ if (size1 === null || size2 === null) {
18
+ return false;
19
+ }
20
+ return size1.width === size2.width && size1.height === size2.height;
21
+ }
22
+ export function measureBoardSize(sceneSize) {
23
+ return Math.min(sceneSize.width, sceneSize.height);
24
+ }
25
+ export function makeBoardRect(sceneSize) {
26
+ const boardSize = measureBoardSize(sceneSize);
27
+ return {
28
+ x: (sceneSize.width - boardSize) / 2,
29
+ y: (sceneSize.height - boardSize) / 2,
30
+ width: boardSize,
31
+ height: boardSize
32
+ };
33
+ }
@@ -1,20 +1,21 @@
1
1
  import { ReadonlyDeep } from 'type-fest';
2
- import { ColorCode, Square } from '../../state/board/types/internal';
3
- export interface SquareRect {
2
+ import { ColorCode, Square } from '../../state/board/types/internal.js';
3
+ export interface Size {
4
+ width: number;
5
+ height: number;
6
+ }
7
+ export type SizeSnapshot = ReadonlyDeep<Size>;
8
+ export interface Rect {
4
9
  x: number;
5
10
  y: number;
6
- size: number;
11
+ width: number;
12
+ height: number;
7
13
  }
8
- export type SquareRectSnapshot = ReadonlyDeep<SquareRect>;
9
- /**
10
- * RenderGeometry represents the derived geometry of the rendered chessboard.
11
- * It includes the board size, square size, orientation, and square rectangle mapping.
12
- *
13
- * It is computed from layout inputs and used by rendering and interaction code.
14
- */
15
- export interface RenderGeometry {
16
- readonly boardSize: number;
14
+ export type RectSnapshot = ReadonlyDeep<Rect>;
15
+ export interface SceneRenderGeometry {
16
+ readonly sceneSize: SizeSnapshot;
17
+ readonly boardRect: RectSnapshot;
17
18
  readonly squareSize: number;
18
19
  readonly orientation: ColorCode;
19
- squareRect(sq: Square): SquareRectSnapshot;
20
+ getSquareRect(sq: Square): RectSnapshot;
20
21
  }
@@ -1,4 +1,3 @@
1
- /**
2
- * Measure board size from container (square board fits within host).
3
- */
4
- export declare function measureBoardSize(container: HTMLElement): number;
1
+ import { Size } from './geometry/types.js';
2
+ export declare function measureSceneSize(container: HTMLElement): Size;
3
+ export declare function isSceneSizeValid(size: Size | null): boolean;
@@ -1,6 +1,6 @@
1
- /**
2
- * Measure board size from container (square board fits within host).
3
- */
4
- export function measureBoardSize(container) {
5
- return Math.min(container.clientWidth, container.clientHeight);
1
+ export function measureSceneSize(container) {
2
+ return { width: container.clientWidth, height: container.clientHeight };
3
+ }
4
+ export function isSceneSizeValid(size) {
5
+ return size !== null && size.width > 0 && size.height > 0;
6
6
  }
@@ -1,4 +1,4 @@
1
- import type { MutationSession } from '../mutation/types';
1
+ import type { MutationSession } from '../mutation/types.js';
2
2
  export type LayoutMutationPayloadByCause = {
3
3
  'layout.refreshGeometry': undefined;
4
4
  };
@@ -1,2 +1,2 @@
1
- import { LayoutInternal, LayoutRefreshOptions } from './types';
1
+ import { LayoutInternal, LayoutRefreshOptions } from './types.js';
2
2
  export declare function layoutRefreshGeometry(state: LayoutInternal, options: LayoutRefreshOptions): boolean;
@@ -1,5 +1,6 @@
1
- import { createRenderGeometry } from './geometry/factory';
2
- import { measureBoardSize } from './helpers';
1
+ import { createRenderGeometry } from './geometry/factory.js';
2
+ import { sceneSizesEqual } from './geometry/helpers.js';
3
+ import { isSceneSizeValid, measureSceneSize } from './helpers.js';
3
4
  export function layoutRefreshGeometry(state, options) {
4
5
  const orientation = options.orientation ?? state.orientation;
5
6
  if (orientation === null) {
@@ -7,23 +8,23 @@ export function layoutRefreshGeometry(state, options) {
7
8
  // For now we throw
8
9
  throw new Error('Orientation is expected to be provided on the first pass of layout.refreshGeometry');
9
10
  }
10
- let boardSize = options.container ? measureBoardSize(options.container) : state.boardSize;
11
- if (boardSize !== null && boardSize <= 0)
12
- boardSize = null;
13
- const changed = boardSize !== state.boardSize || orientation !== state.orientation;
11
+ let sceneSize = options.container ? measureSceneSize(options.container) : state.sceneSize;
12
+ if (sceneSize !== null && !isSceneSizeValid(sceneSize))
13
+ sceneSize = null;
14
+ const changed = !sceneSizesEqual(sceneSize, state.sceneSize) || orientation !== state.orientation;
14
15
  if (!changed) {
15
16
  return false; // no-op, no relevant changes
16
17
  }
17
18
  // Update the state
18
- state.boardSize = boardSize;
19
+ state.sceneSize = sceneSize;
19
20
  state.orientation = orientation;
20
- if (boardSize === null || orientation === null) {
21
+ if (sceneSize === null || orientation === null) {
21
22
  // General invalid-geometry rule. Orientation is currently guarded above,
22
23
  // but this branch stays explicit in case null orientation is allowed later.
23
24
  state.geometry = null;
24
25
  }
25
26
  else {
26
- state.geometry = createRenderGeometry(boardSize, orientation);
27
+ state.geometry = createRenderGeometry(sceneSize, orientation);
27
28
  }
28
29
  state.layoutEpoch++;
29
30
  return true;