@mirasen/chessboard 0.1.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.
- package/CHANGELOG.md +7 -0
- package/LICENSE +21 -0
- package/README.md +96 -0
- package/assets/pieces/chessnut/ATTRIBUTION.md +13 -0
- package/assets/pieces/chessnut/LICENSE.txt +202 -0
- package/assets/pieces/chessnut/bB.svg +58 -0
- package/assets/pieces/chessnut/bK.svg +51 -0
- package/assets/pieces/chessnut/bN.svg +19 -0
- package/assets/pieces/chessnut/bP.svg +17 -0
- package/assets/pieces/chessnut/bQ.svg +97 -0
- package/assets/pieces/chessnut/bR.svg +34 -0
- package/assets/pieces/chessnut/wB.svg +61 -0
- package/assets/pieces/chessnut/wK.svg +71 -0
- package/assets/pieces/chessnut/wN.svg +19 -0
- package/assets/pieces/chessnut/wP.svg +17 -0
- package/assets/pieces/chessnut/wQ.svg +40 -0
- package/assets/pieces/chessnut/wR.svg +38 -0
- package/dist/animation/planner.d.ts +6 -0
- package/dist/animation/planner.js +128 -0
- package/dist/animation/render/fade.d.ts +7 -0
- package/dist/animation/render/fade.js +24 -0
- package/dist/animation/render/move.d.ts +7 -0
- package/dist/animation/render/move.js +28 -0
- package/dist/animation/render/plan.d.ts +14 -0
- package/dist/animation/render/plan.js +69 -0
- package/dist/animation/render/static.d.ts +7 -0
- package/dist/animation/render/static.js +21 -0
- package/dist/animation/render/types.d.ts +21 -0
- package/dist/animation/render/types.js +1 -0
- package/dist/animation/types.d.ts +46 -0
- package/dist/animation/types.js +6 -0
- package/dist/extensions/animation/factory.d.ts +3 -0
- package/dist/extensions/animation/factory.js +88 -0
- package/dist/extensions/animation/types.d.ts +11 -0
- package/dist/extensions/animation/types.js +1 -0
- package/dist/extensions/factory/main.d.ts +2 -0
- package/dist/extensions/factory/main.js +101 -0
- package/dist/extensions/factory/runtime.d.ts +5 -0
- package/dist/extensions/factory/runtime.js +43 -0
- package/dist/extensions/first-party/active-target/factory.d.ts +2 -0
- package/dist/extensions/first-party/active-target/factory.js +109 -0
- package/dist/extensions/first-party/active-target/types.d.ts +25 -0
- package/dist/extensions/first-party/active-target/types.js +15 -0
- package/dist/extensions/first-party/board-events/factory.d.ts +2 -0
- package/dist/extensions/first-party/board-events/factory.js +65 -0
- package/dist/extensions/first-party/board-events/types.d.ts +27 -0
- package/dist/extensions/first-party/board-events/types.js +2 -0
- package/dist/extensions/first-party/common/helpers.d.ts +8 -0
- package/dist/extensions/first-party/common/helpers.js +33 -0
- package/dist/extensions/first-party/common/types.d.ts +10 -0
- package/dist/extensions/first-party/common/types.js +1 -0
- package/dist/extensions/first-party/last-move/factory.d.ts +2 -0
- package/dist/extensions/first-party/last-move/factory.js +106 -0
- package/dist/extensions/first-party/last-move/types.d.ts +19 -0
- package/dist/extensions/first-party/last-move/types.js +6 -0
- package/dist/extensions/first-party/legal-moves/factory.d.ts +2 -0
- package/dist/extensions/first-party/legal-moves/factory.js +101 -0
- package/dist/extensions/first-party/legal-moves/types.d.ts +29 -0
- package/dist/extensions/first-party/legal-moves/types.js +19 -0
- package/dist/extensions/first-party/main-renderer/animation/factory.d.ts +4 -0
- package/dist/extensions/first-party/main-renderer/animation/factory.js +35 -0
- package/dist/extensions/first-party/main-renderer/animation/render.d.ts +7 -0
- package/dist/extensions/first-party/main-renderer/animation/render.js +46 -0
- package/dist/extensions/first-party/main-renderer/animation/types.d.ts +24 -0
- package/dist/extensions/first-party/main-renderer/animation/types.js +1 -0
- package/dist/extensions/first-party/main-renderer/animation/update.d.ts +3 -0
- package/dist/extensions/first-party/main-renderer/animation/update.js +40 -0
- package/dist/extensions/first-party/main-renderer/board/factory.d.ts +3 -0
- package/dist/extensions/first-party/main-renderer/board/factory.js +16 -0
- package/dist/extensions/first-party/main-renderer/board/render.d.ts +3 -0
- package/dist/extensions/first-party/main-renderer/board/render.js +24 -0
- package/dist/extensions/first-party/main-renderer/board/types.d.ts +10 -0
- package/dist/extensions/first-party/main-renderer/board/types.js +1 -0
- package/dist/extensions/first-party/main-renderer/board/update.d.ts +3 -0
- package/dist/extensions/first-party/main-renderer/board/update.js +27 -0
- package/dist/extensions/first-party/main-renderer/coordinates/factory.d.ts +3 -0
- package/dist/extensions/first-party/main-renderer/coordinates/factory.js +9 -0
- package/dist/extensions/first-party/main-renderer/coordinates/render.d.ts +3 -0
- package/dist/extensions/first-party/main-renderer/coordinates/render.js +60 -0
- package/dist/extensions/first-party/main-renderer/coordinates/types.d.ts +8 -0
- package/dist/extensions/first-party/main-renderer/coordinates/types.js +1 -0
- package/dist/extensions/first-party/main-renderer/drag/factory.d.ts +4 -0
- package/dist/extensions/first-party/main-renderer/drag/factory.js +23 -0
- package/dist/extensions/first-party/main-renderer/drag/render.d.ts +3 -0
- package/dist/extensions/first-party/main-renderer/drag/render.js +27 -0
- package/dist/extensions/first-party/main-renderer/drag/types.d.ts +16 -0
- package/dist/extensions/first-party/main-renderer/drag/types.js +1 -0
- package/dist/extensions/first-party/main-renderer/drag/update.d.ts +3 -0
- package/dist/extensions/first-party/main-renderer/drag/update.js +23 -0
- package/dist/extensions/first-party/main-renderer/factory.d.ts +2 -0
- package/dist/extensions/first-party/main-renderer/factory.js +95 -0
- package/dist/extensions/first-party/main-renderer/normalize.d.ts +4 -0
- package/dist/extensions/first-party/main-renderer/normalize.js +27 -0
- package/dist/extensions/first-party/main-renderer/pieces/factory.d.ts +3 -0
- package/dist/extensions/first-party/main-renderer/pieces/factory.js +27 -0
- package/dist/extensions/first-party/main-renderer/pieces/render.d.ts +3 -0
- package/dist/extensions/first-party/main-renderer/pieces/render.js +45 -0
- package/dist/extensions/first-party/main-renderer/pieces/suppress.d.ts +5 -0
- package/dist/extensions/first-party/main-renderer/pieces/suppress.js +9 -0
- package/dist/extensions/first-party/main-renderer/pieces/types.d.ts +20 -0
- package/dist/extensions/first-party/main-renderer/pieces/types.js +1 -0
- package/dist/extensions/first-party/main-renderer/pieces/update.d.ts +6 -0
- package/dist/extensions/first-party/main-renderer/pieces/update.js +31 -0
- package/dist/extensions/first-party/main-renderer/types/extension.d.ts +15 -0
- package/dist/extensions/first-party/main-renderer/types/extension.js +10 -0
- package/dist/extensions/first-party/main-renderer/types/input.d.ts +4 -0
- package/dist/extensions/first-party/main-renderer/types/input.js +1 -0
- package/dist/extensions/first-party/main-renderer/types/instance.d.ts +16 -0
- package/dist/extensions/first-party/main-renderer/types/instance.js +1 -0
- package/dist/extensions/first-party/main-renderer/types/internal.d.ts +17 -0
- package/dist/extensions/first-party/main-renderer/types/internal.js +30 -0
- package/dist/extensions/first-party/main-renderer/types/template.d.ts +5 -0
- package/dist/extensions/first-party/main-renderer/types/template.js +1 -0
- package/dist/extensions/first-party/selected-square/factory.d.ts +2 -0
- package/dist/extensions/first-party/selected-square/factory.js +88 -0
- package/dist/extensions/first-party/selected-square/types.d.ts +18 -0
- package/dist/extensions/first-party/selected-square/types.js +6 -0
- package/dist/extensions/index.d.ts +8 -0
- package/dist/extensions/index.js +6 -0
- package/dist/extensions/invalidation/factory.d.ts +2 -0
- package/dist/extensions/invalidation/factory.js +22 -0
- package/dist/extensions/invalidation/types.d.ts +11 -0
- package/dist/extensions/invalidation/types.js +1 -0
- package/dist/extensions/types/basic/animation.d.ts +28 -0
- package/dist/extensions/types/basic/animation.js +6 -0
- package/dist/extensions/types/basic/events.d.ts +34 -0
- package/dist/extensions/types/basic/events.js +7 -0
- package/dist/extensions/types/basic/mount.d.ts +7 -0
- package/dist/extensions/types/basic/mount.js +14 -0
- package/dist/extensions/types/basic/render.d.ts +9 -0
- package/dist/extensions/types/basic/render.js +1 -0
- package/dist/extensions/types/basic/transient-visuals.d.ts +10 -0
- package/dist/extensions/types/basic/transient-visuals.js +1 -0
- package/dist/extensions/types/basic/update.d.ts +16 -0
- package/dist/extensions/types/basic/update.js +11 -0
- package/dist/extensions/types/context/animation.d.ts +31 -0
- package/dist/extensions/types/context/animation.js +9 -0
- package/dist/extensions/types/context/render.d.ts +6 -0
- package/dist/extensions/types/context/render.js +1 -0
- package/dist/extensions/types/context/transient-visuals.d.ts +7 -0
- package/dist/extensions/types/context/transient-visuals.js +1 -0
- package/dist/extensions/types/context/ui-move.d.ts +16 -0
- package/dist/extensions/types/context/ui-move.js +1 -0
- package/dist/extensions/types/context/update.d.ts +25 -0
- package/dist/extensions/types/context/update.js +10 -0
- package/dist/extensions/types/extension.d.ts +40 -0
- package/dist/extensions/types/extension.js +1 -0
- package/dist/extensions/types/main.d.ts +44 -0
- package/dist/extensions/types/main.js +1 -0
- package/dist/extensions/types/surface/commands.d.ts +26 -0
- package/dist/extensions/types/surface/commands.js +1 -0
- package/dist/extensions/types/surface/events.d.ts +5 -0
- package/dist/extensions/types/surface/events.js +1 -0
- package/dist/extensions/types/surface/main.d.ts +10 -0
- package/dist/extensions/types/surface/main.js +1 -0
- package/dist/extensions/types/surface/transient-visuals.d.ts +4 -0
- package/dist/extensions/types/surface/transient-visuals.js +1 -0
- package/dist/extensions/types/wrapper.d.ts +26 -0
- package/dist/extensions/types/wrapper.js +11 -0
- package/dist/extensions/update.d.ts +4 -0
- package/dist/extensions/update.js +29 -0
- package/dist/helpers/util.d.ts +1 -0
- package/dist/helpers/util.js +9 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +1 -0
- package/dist/layout/factory.d.ts +2 -0
- package/dist/layout/factory.js +33 -0
- package/dist/layout/geometry/factory.d.ts +12 -0
- package/dist/layout/geometry/factory.js +33 -0
- package/dist/layout/geometry/types.d.ts +20 -0
- package/dist/layout/geometry/types.js +1 -0
- package/dist/layout/helpers.d.ts +4 -0
- package/dist/layout/helpers.js +6 -0
- package/dist/layout/mutation.d.ts +6 -0
- package/dist/layout/mutation.js +1 -0
- package/dist/layout/reducers.d.ts +2 -0
- package/dist/layout/reducers.js +30 -0
- package/dist/layout/types.d.ts +23 -0
- package/dist/layout/types.js +1 -0
- package/dist/mutation/pipeline.d.ts +2 -0
- package/dist/mutation/pipeline.js +36 -0
- package/dist/mutation/session.d.ts +3 -0
- package/dist/mutation/session.js +66 -0
- package/dist/mutation/types.d.ts +26 -0
- package/dist/mutation/types.js +1 -0
- package/dist/render/factory.d.ts +2 -0
- package/dist/render/factory.js +117 -0
- package/dist/render/mount.d.ts +3 -0
- package/dist/render/mount.js +28 -0
- package/dist/render/rendering/animation.d.ts +13 -0
- package/dist/render/rendering/animation.js +92 -0
- package/dist/render/rendering/helpers.d.ts +3 -0
- package/dist/render/rendering/helpers.js +10 -0
- package/dist/render/rendering/state.d.ts +4 -0
- package/dist/render/rendering/state.js +48 -0
- package/dist/render/rendering/visuals.d.ts +3 -0
- package/dist/render/rendering/visuals.js +21 -0
- package/dist/render/scheduler/scheduler.d.ts +2 -0
- package/dist/render/scheduler/scheduler.js +53 -0
- package/dist/render/scheduler/types.d.ts +12 -0
- package/dist/render/scheduler/types.js +1 -0
- package/dist/render/svg/factory.d.ts +4 -0
- package/dist/render/svg/factory.js +38 -0
- package/dist/render/svg/helpers.d.ts +18 -0
- package/dist/render/svg/helpers.js +34 -0
- package/dist/render/types.d.ts +42 -0
- package/dist/render/types.js +1 -0
- package/dist/runtime/factory/helpers.d.ts +6 -0
- package/dist/runtime/factory/helpers.js +42 -0
- package/dist/runtime/factory/input.d.ts +3 -0
- package/dist/runtime/factory/input.js +98 -0
- package/dist/runtime/factory/main.d.ts +2 -0
- package/dist/runtime/factory/main.js +182 -0
- package/dist/runtime/factory/ui-move.d.ts +4 -0
- package/dist/runtime/factory/ui-move.js +84 -0
- package/dist/runtime/input/adapter/factory.d.ts +2 -0
- package/dist/runtime/input/adapter/factory.js +55 -0
- package/dist/runtime/input/adapter/helpers.d.ts +5 -0
- package/dist/runtime/input/adapter/helpers.js +23 -0
- package/dist/runtime/input/adapter/pointer.d.ts +13 -0
- package/dist/runtime/input/adapter/pointer.js +97 -0
- package/dist/runtime/input/adapter/types.d.ts +16 -0
- package/dist/runtime/input/adapter/types.js +1 -0
- package/dist/runtime/input/controller/factory.d.ts +2 -0
- package/dist/runtime/input/controller/factory.js +32 -0
- package/dist/runtime/input/controller/helpers.d.ts +3 -0
- package/dist/runtime/input/controller/helpers.js +12 -0
- package/dist/runtime/input/controller/pointer.d.ts +7 -0
- package/dist/runtime/input/controller/pointer.js +104 -0
- package/dist/runtime/input/controller/transient-visuals.d.ts +3 -0
- package/dist/runtime/input/controller/transient-visuals.js +12 -0
- package/dist/runtime/input/controller/types.d.ts +25 -0
- package/dist/runtime/input/controller/types.js +1 -0
- package/dist/runtime/layout.d.ts +2 -0
- package/dist/runtime/layout.js +10 -0
- package/dist/runtime/lifecycle.d.ts +12 -0
- package/dist/runtime/lifecycle.js +49 -0
- package/dist/runtime/mutation/extension-update.d.ts +2 -0
- package/dist/runtime/mutation/extension-update.js +26 -0
- package/dist/runtime/mutation/factory.d.ts +2 -0
- package/dist/runtime/mutation/factory.js +47 -0
- package/dist/runtime/mutation/interaction.d.ts +2 -0
- package/dist/runtime/mutation/interaction.js +34 -0
- package/dist/runtime/mutation/invalidation.d.ts +0 -0
- package/dist/runtime/mutation/invalidation.js +2 -0
- package/dist/runtime/mutation/last-move.d.ts +3 -0
- package/dist/runtime/mutation/last-move.js +19 -0
- package/dist/runtime/mutation/layout.d.ts +2 -0
- package/dist/runtime/mutation/layout.js +8 -0
- package/dist/runtime/mutation/pipeline.d.ts +22 -0
- package/dist/runtime/mutation/pipeline.js +1 -0
- package/dist/runtime/mutation/request-render.d.ts +2 -0
- package/dist/runtime/mutation/request-render.js +29 -0
- package/dist/runtime/mutation/run.d.ts +2 -0
- package/dist/runtime/mutation/run.js +3 -0
- package/dist/runtime/mutation/types.d.ts +14 -0
- package/dist/runtime/mutation/types.js +1 -0
- package/dist/runtime/types/main.d.ts +36 -0
- package/dist/runtime/types/main.js +1 -0
- package/dist/runtime/types/ui-move.d.ts +9 -0
- package/dist/runtime/types/ui-move.js +1 -0
- package/dist/state/board/check.d.ts +27 -0
- package/dist/state/board/check.js +148 -0
- package/dist/state/board/coords.d.ts +4 -0
- package/dist/state/board/coords.js +9 -0
- package/dist/state/board/denormalize.d.ts +11 -0
- package/dist/state/board/denormalize.js +77 -0
- package/dist/state/board/factory.d.ts +3 -0
- package/dist/state/board/factory.js +46 -0
- package/dist/state/board/mutation.d.ts +9 -0
- package/dist/state/board/mutation.js +1 -0
- package/dist/state/board/normalize.d.ts +8 -0
- package/dist/state/board/normalize.js +76 -0
- package/dist/state/board/piece.d.ts +3 -0
- package/dist/state/board/piece.js +11 -0
- package/dist/state/board/position.d.ts +4 -0
- package/dist/state/board/position.js +94 -0
- package/dist/state/board/reducers.d.ts +8 -0
- package/dist/state/board/reducers.js +80 -0
- package/dist/state/board/types/input.d.ts +35 -0
- package/dist/state/board/types/input.js +1 -0
- package/dist/state/board/types/internal.d.ts +54 -0
- package/dist/state/board/types/internal.js +17 -0
- package/dist/state/board/types/main.d.ts +18 -0
- package/dist/state/board/types/main.js +1 -0
- package/dist/state/board/types/output.d.ts +5 -0
- package/dist/state/board/types/output.js +1 -0
- package/dist/state/board/types/template.d.ts +23 -0
- package/dist/state/board/types/template.js +1 -0
- package/dist/state/change/factory.d.ts +2 -0
- package/dist/state/change/factory.js +28 -0
- package/dist/state/change/helpers.d.ts +8 -0
- package/dist/state/change/helpers.js +86 -0
- package/dist/state/change/mutation.d.ts +6 -0
- package/dist/state/change/mutation.js +1 -0
- package/dist/state/change/reducers.d.ts +5 -0
- package/dist/state/change/reducers.js +16 -0
- package/dist/state/change/types.d.ts +17 -0
- package/dist/state/change/types.js +1 -0
- package/dist/state/factory.d.ts +2 -0
- package/dist/state/factory.js +24 -0
- package/dist/state/interaction/factory.d.ts +2 -0
- package/dist/state/interaction/factory.js +83 -0
- package/dist/state/interaction/helpers.d.ts +4 -0
- package/dist/state/interaction/helpers.js +16 -0
- package/dist/state/interaction/movability.d.ts +5 -0
- package/dist/state/interaction/movability.js +87 -0
- package/dist/state/interaction/mutation.d.ts +11 -0
- package/dist/state/interaction/mutation.js +1 -0
- package/dist/state/interaction/normalize.d.ts +5 -0
- package/dist/state/interaction/normalize.js +50 -0
- package/dist/state/interaction/reducers.d.ts +11 -0
- package/dist/state/interaction/reducers.js +81 -0
- package/dist/state/interaction/types/input.d.ts +18 -0
- package/dist/state/interaction/types/input.js +1 -0
- package/dist/state/interaction/types/internal.d.ts +35 -0
- package/dist/state/interaction/types/internal.js +1 -0
- package/dist/state/interaction/types/main.d.ts +33 -0
- package/dist/state/interaction/types/main.js +1 -0
- package/dist/state/types.d.ts +30 -0
- package/dist/state/types.js +1 -0
- package/dist/state/view/factory.d.ts +2 -0
- package/dist/state/view/factory.js +24 -0
- package/dist/state/view/mutation.d.ts +5 -0
- package/dist/state/view/mutation.js +1 -0
- package/dist/state/view/reducers.d.ts +3 -0
- package/dist/state/view/reducers.js +6 -0
- package/dist/state/view/types/internal.d.ts +6 -0
- package/dist/state/view/types/internal.js +1 -0
- package/dist/state/view/types/main.d.ts +12 -0
- package/dist/state/view/types/main.js +1 -0
- package/dist/wrapper/factory.d.ts +3 -0
- package/dist/wrapper/factory.js +61 -0
- package/dist/wrapper/types.d.ts +56 -0
- package/dist/wrapper/types.js +1 -0
- package/package.json +98 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { createBoardState } from './board/factory';
|
|
2
|
+
import { createChangeState } from './change/factory';
|
|
3
|
+
import { createInteractionState } from './interaction/factory';
|
|
4
|
+
import { createViewState } from './view/factory';
|
|
5
|
+
function createRuntimeStateInternal(options) {
|
|
6
|
+
return {
|
|
7
|
+
board: createBoardState(options.board ?? {}),
|
|
8
|
+
view: createViewState(options.view ?? {}),
|
|
9
|
+
interaction: createInteractionState(options.interaction ?? {}),
|
|
10
|
+
change: createChangeState()
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export function createRuntimeState(options) {
|
|
14
|
+
const internalState = createRuntimeStateInternal(options);
|
|
15
|
+
return {
|
|
16
|
+
...internalState,
|
|
17
|
+
getSnapshot: () => ({
|
|
18
|
+
board: internalState.board.getSnapshot(),
|
|
19
|
+
view: internalState.view.getSnapshot(),
|
|
20
|
+
interaction: internalState.interaction.getSnapshot(),
|
|
21
|
+
change: internalState.change.getSnapshot()
|
|
22
|
+
})
|
|
23
|
+
};
|
|
24
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import assert from '@ktarmyshov/assert';
|
|
2
|
+
import { cloneDeep } from 'es-toolkit';
|
|
3
|
+
import { updateActiveDestinations } from './helpers';
|
|
4
|
+
import { normalizeMovability } from './normalize';
|
|
5
|
+
import { interactionClear, interactionClearActive, interactionSetDragSession, interactionSetMovability, interactionSetSelected, interactionUpdateDragSessionCurrentTarget } from './reducers';
|
|
6
|
+
const DefaultMovabilityDisabled = { mode: 0 /* MovabilityModeCode.Disabled */ };
|
|
7
|
+
/**
|
|
8
|
+
* Create a fresh interaction state with all fields set to null or false.
|
|
9
|
+
*/
|
|
10
|
+
function createInteractionStateInternal(options) {
|
|
11
|
+
const movability = options.movability
|
|
12
|
+
? normalizeMovability(options.movability)
|
|
13
|
+
: DefaultMovabilityDisabled;
|
|
14
|
+
return {
|
|
15
|
+
movability,
|
|
16
|
+
selected: null,
|
|
17
|
+
activeDestinations: new Map(),
|
|
18
|
+
dragSession: null
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export function createInteractionState(options) {
|
|
22
|
+
const internalState = createInteractionStateInternal(options);
|
|
23
|
+
return {
|
|
24
|
+
get selected() {
|
|
25
|
+
return cloneDeep(internalState.selected);
|
|
26
|
+
},
|
|
27
|
+
setSelected(selected, mutationSession) {
|
|
28
|
+
const changed = mutationSession.addMutation('state.interaction.setSelectedSquare', interactionSetSelected(internalState, selected));
|
|
29
|
+
if (!changed)
|
|
30
|
+
return false; // no-op
|
|
31
|
+
updateActiveDestinations(internalState, mutationSession);
|
|
32
|
+
return changed;
|
|
33
|
+
},
|
|
34
|
+
get movability() {
|
|
35
|
+
return cloneDeep(internalState.movability);
|
|
36
|
+
},
|
|
37
|
+
setMovability(movability, mutationSession) {
|
|
38
|
+
const changed = mutationSession.addMutation('state.interaction.setMovability', interactionSetMovability(internalState, normalizeMovability(movability)));
|
|
39
|
+
if (!changed)
|
|
40
|
+
return false; // no-op
|
|
41
|
+
updateActiveDestinations(internalState, mutationSession);
|
|
42
|
+
return changed;
|
|
43
|
+
},
|
|
44
|
+
get activeDestinations() {
|
|
45
|
+
return cloneDeep(internalState.activeDestinations);
|
|
46
|
+
},
|
|
47
|
+
updateActiveDestinations(mutationSession) {
|
|
48
|
+
return updateActiveDestinations(internalState, mutationSession);
|
|
49
|
+
},
|
|
50
|
+
get dragSession() {
|
|
51
|
+
return internalState.dragSession ? { ...internalState.dragSession } : null;
|
|
52
|
+
},
|
|
53
|
+
setDragSession(session, mutationSession) {
|
|
54
|
+
// Assert that the selected is the same as the source of the drag session when setting a lifted-piece-drag session
|
|
55
|
+
if (session) {
|
|
56
|
+
assert(internalState.selected, 'There must be a selected piece to start a drag session');
|
|
57
|
+
if (session.type === 'lifted-piece-drag') {
|
|
58
|
+
assert(internalState.selected, 'There must be a selected piece to start a lifted-piece-drag session');
|
|
59
|
+
assert(session.sourceSquare === internalState.selected.square, 'The source square of the lifted-piece-drag session must match the selected square');
|
|
60
|
+
assert(session.sourcePieceCode === internalState.selected.pieceCode, 'The source piece code of the lifted-piece-drag session must match the selected piece code');
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return mutationSession.addMutation('state.interaction.setDragSession', interactionSetDragSession(internalState, session));
|
|
64
|
+
},
|
|
65
|
+
updateDragSessionCurrentTarget(sq, mutationSession) {
|
|
66
|
+
assert(internalState.dragSession, 'There must be an active drag session to update its current target');
|
|
67
|
+
return mutationSession.addMutation('state.interaction.updateDragSessionCurrentTarget', interactionUpdateDragSessionCurrentTarget(internalState, sq));
|
|
68
|
+
},
|
|
69
|
+
clear(mutationSession) {
|
|
70
|
+
const changed = mutationSession.addMutation('state.interaction.clear', interactionClear(internalState));
|
|
71
|
+
if (!changed)
|
|
72
|
+
return false; // no-op
|
|
73
|
+
updateActiveDestinations(internalState, mutationSession);
|
|
74
|
+
return true;
|
|
75
|
+
},
|
|
76
|
+
clearActive(mutationSession) {
|
|
77
|
+
return mutationSession.addMutation('state.interaction.clearActive', interactionClearActive(internalState));
|
|
78
|
+
},
|
|
79
|
+
getSnapshot() {
|
|
80
|
+
return cloneDeep(internalState);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { InteractionStateMutationSession } from './mutation';
|
|
2
|
+
import { InteractionStateInternal, InteractionStateSelected } from './types/main';
|
|
3
|
+
export declare function selectedEqual(a: InteractionStateSelected | null, b: InteractionStateSelected | null): boolean;
|
|
4
|
+
export declare function updateActiveDestinations(state: InteractionStateInternal, mutationSession: InteractionStateMutationSession): boolean;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { getActiveDestinations } from './movability';
|
|
2
|
+
import { interactionSetActiveDestinations } from './reducers';
|
|
3
|
+
export function selectedEqual(a, b) {
|
|
4
|
+
if (a === b)
|
|
5
|
+
return true;
|
|
6
|
+
if (a === null || b === null)
|
|
7
|
+
return false;
|
|
8
|
+
return a.square === b.square && a.pieceCode === b.pieceCode;
|
|
9
|
+
}
|
|
10
|
+
export function updateActiveDestinations(state, mutationSession) {
|
|
11
|
+
if (!state.selected) {
|
|
12
|
+
return mutationSession.addMutation('state.interaction.updateActiveDestinations', interactionSetActiveDestinations(state, new Map()));
|
|
13
|
+
}
|
|
14
|
+
const activeDests = getActiveDestinations(state, state.selected.square);
|
|
15
|
+
return mutationSession.addMutation('state.interaction.updateActiveDestinations', interactionSetActiveDestinations(state, activeDests));
|
|
16
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Square } from '../board/types/internal';
|
|
2
|
+
import { MoveDestinationSnapshot, type MovabilitySnapshot } from './types/internal';
|
|
3
|
+
import { InteractionStateInternal } from './types/main';
|
|
4
|
+
export declare function movabilitiesEqual(a: MovabilitySnapshot, b: MovabilitySnapshot): boolean;
|
|
5
|
+
export declare function getActiveDestinations(state: InteractionStateInternal, from: Square): ReadonlyMap<Square, MoveDestinationSnapshot>;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { setsEqual } from '../../helpers/util';
|
|
2
|
+
import { assertValidSquare } from '../board/check';
|
|
3
|
+
function moveDestinationsEqual(a, b) {
|
|
4
|
+
if (a === b)
|
|
5
|
+
return true;
|
|
6
|
+
if (a == null || b == null)
|
|
7
|
+
return false;
|
|
8
|
+
return (a.to === b.to &&
|
|
9
|
+
a.capturedSquare === b.capturedSquare &&
|
|
10
|
+
a.secondary?.from === b.secondary?.from &&
|
|
11
|
+
a.secondary?.to === b.secondary?.to &&
|
|
12
|
+
setsEqual(new Set(a.promotedTo ? a.promotedTo : []), new Set(b.promotedTo ? b.promotedTo : [])));
|
|
13
|
+
}
|
|
14
|
+
function recordToDestinationsMap(record) {
|
|
15
|
+
const map = new Map();
|
|
16
|
+
for (const [key, dests] of Object.entries(record)) {
|
|
17
|
+
if (dests) {
|
|
18
|
+
const square = Number(key);
|
|
19
|
+
assertValidSquare(square);
|
|
20
|
+
if (map.has(square)) {
|
|
21
|
+
throw new RangeError(`Duplicate square key in movability destinations: ${key}`);
|
|
22
|
+
}
|
|
23
|
+
map.set(square, dests);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return map;
|
|
27
|
+
}
|
|
28
|
+
export function movabilitiesEqual(a, b) {
|
|
29
|
+
if (a === b)
|
|
30
|
+
return true;
|
|
31
|
+
if (a.mode !== b.mode)
|
|
32
|
+
return false;
|
|
33
|
+
switch (a.mode) {
|
|
34
|
+
case 0 /* MovabilityModeCode.Disabled */:
|
|
35
|
+
return true;
|
|
36
|
+
case 1 /* MovabilityModeCode.Free */:
|
|
37
|
+
return true;
|
|
38
|
+
case 2 /* MovabilityModeCode.Strict */: {
|
|
39
|
+
const aDests = a.destinations;
|
|
40
|
+
const bDests = b.destinations;
|
|
41
|
+
const aIsResolver = typeof aDests === 'function';
|
|
42
|
+
const bIsResolver = typeof bDests === 'function';
|
|
43
|
+
if (aIsResolver && bIsResolver)
|
|
44
|
+
return aDests === bDests;
|
|
45
|
+
if (aIsResolver !== bIsResolver)
|
|
46
|
+
return false;
|
|
47
|
+
const aMap = recordToDestinationsMap(aDests);
|
|
48
|
+
const bMap = recordToDestinationsMap(bDests);
|
|
49
|
+
if (aMap.size !== bMap.size)
|
|
50
|
+
return false;
|
|
51
|
+
for (const [sq, aDestArr] of aMap) {
|
|
52
|
+
const bDestArr = bMap.get(sq);
|
|
53
|
+
if (!bDestArr)
|
|
54
|
+
return false;
|
|
55
|
+
if (aDestArr.length !== bDestArr.length)
|
|
56
|
+
return false;
|
|
57
|
+
for (let i = 0; i < aDestArr.length; i++) {
|
|
58
|
+
if (!moveDestinationsEqual(aDestArr[i], bDestArr[i]))
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
default:
|
|
65
|
+
throw new RangeError(`Unhandled movability mode code: ${a}`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
export function getActiveDestinations(state, from) {
|
|
69
|
+
const movability = state.movability;
|
|
70
|
+
if (movability.mode === 0 /* MovabilityModeCode.Disabled */)
|
|
71
|
+
return new Map();
|
|
72
|
+
if (movability.mode === 1 /* MovabilityModeCode.Free */)
|
|
73
|
+
return new Map();
|
|
74
|
+
// strict mode: normalize and build a Map keyed by destination square
|
|
75
|
+
const dests = getDestinationsForSource(movability.destinations, from) ?? [];
|
|
76
|
+
const map = new Map();
|
|
77
|
+
for (const dest of dests) {
|
|
78
|
+
map.set(dest.to, dest);
|
|
79
|
+
}
|
|
80
|
+
return map;
|
|
81
|
+
}
|
|
82
|
+
function getDestinationsForSource(destinations, source) {
|
|
83
|
+
if (typeof destinations === 'function') {
|
|
84
|
+
return destinations(source);
|
|
85
|
+
}
|
|
86
|
+
return destinations[source];
|
|
87
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { MutationSession } from '../../mutation/types';
|
|
2
|
+
export type InteractionStateMutationPayloadByCause = {
|
|
3
|
+
'state.interaction.setSelectedSquare': undefined;
|
|
4
|
+
'state.interaction.setDragSession': undefined;
|
|
5
|
+
'state.interaction.updateDragSessionCurrentTarget': undefined;
|
|
6
|
+
'state.interaction.clear': undefined;
|
|
7
|
+
'state.interaction.clearActive': undefined;
|
|
8
|
+
'state.interaction.setMovability': undefined;
|
|
9
|
+
'state.interaction.updateActiveDestinations': undefined;
|
|
10
|
+
};
|
|
11
|
+
export type InteractionStateMutationSession = MutationSession<InteractionStateMutationPayloadByCause>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ReadonlyDeep } from 'type-fest';
|
|
2
|
+
import { MovabilityInput, MoveDestinationInput } from './types/input';
|
|
3
|
+
import { Movability, MoveDestination } from './types/internal';
|
|
4
|
+
export declare function normalizeMoveDestinationInput(destination: ReadonlyDeep<MoveDestinationInput>): MoveDestination;
|
|
5
|
+
export declare function normalizeMovability(movability: MovabilityInput): Movability;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { denormalizeSquare } from '../board/denormalize';
|
|
2
|
+
import { normalizeRolePromotion, normalizeSquare } from '../board/normalize';
|
|
3
|
+
export function normalizeMoveDestinationInput(destination) {
|
|
4
|
+
return {
|
|
5
|
+
to: normalizeSquare(destination.to),
|
|
6
|
+
...(destination.capturedSquare && {
|
|
7
|
+
capturedSquare: normalizeSquare(destination.capturedSquare)
|
|
8
|
+
}),
|
|
9
|
+
...(destination.secondary && {
|
|
10
|
+
secondary: {
|
|
11
|
+
from: normalizeSquare(destination.secondary.from),
|
|
12
|
+
to: normalizeSquare(destination.secondary.to)
|
|
13
|
+
}
|
|
14
|
+
}),
|
|
15
|
+
...(destination.promotedTo && {
|
|
16
|
+
promotedTo: destination.promotedTo.map(normalizeRolePromotion)
|
|
17
|
+
})
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export function normalizeMovability(movability) {
|
|
21
|
+
if (movability.mode === 'disabled') {
|
|
22
|
+
return { mode: 0 /* MovabilityModeCode.Disabled */ };
|
|
23
|
+
}
|
|
24
|
+
if (movability.mode === 'free') {
|
|
25
|
+
return { mode: 1 /* MovabilityModeCode.Free */ };
|
|
26
|
+
}
|
|
27
|
+
// Strict mode
|
|
28
|
+
let destinations;
|
|
29
|
+
if (typeof movability.destinations === 'function') {
|
|
30
|
+
const resolverInput = movability.destinations;
|
|
31
|
+
destinations = (source) => {
|
|
32
|
+
const inputDests = resolverInput(denormalizeSquare(source));
|
|
33
|
+
return inputDests ? inputDests.map(normalizeMoveDestinationInput) : undefined;
|
|
34
|
+
};
|
|
35
|
+
return {
|
|
36
|
+
mode: 2 /* MovabilityModeCode.Strict */,
|
|
37
|
+
destinations
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
// Destinations as record
|
|
41
|
+
const recordInput = movability.destinations;
|
|
42
|
+
const destinationsRecord = {};
|
|
43
|
+
for (const [sqStr, destInputs] of Object.entries(recordInput)) {
|
|
44
|
+
destinationsRecord[normalizeSquare(sqStr)] = destInputs.map(normalizeMoveDestinationInput);
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
mode: 2 /* MovabilityModeCode.Strict */,
|
|
48
|
+
destinations: destinationsRecord
|
|
49
|
+
};
|
|
50
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ReadonlyDeep } from 'type-fest';
|
|
2
|
+
import type { Square } from '../board/types/internal';
|
|
3
|
+
import { Movability, type DragSessionSnapshot, type MoveDestination } from './types/internal';
|
|
4
|
+
import { InteractionStateInternal, InteractionStateSelected } from './types/main';
|
|
5
|
+
export declare function interactionSetSelected(state: InteractionStateInternal, selected: InteractionStateSelected | null): boolean;
|
|
6
|
+
export declare function interactionSetMovability(state: InteractionStateInternal, m: Movability): boolean;
|
|
7
|
+
export declare function interactionSetActiveDestinations(state: InteractionStateInternal, dests: ReadonlyMap<Square, ReadonlyDeep<MoveDestination>>): boolean;
|
|
8
|
+
export declare function interactionSetDragSession(state: InteractionStateInternal, session: DragSessionSnapshot | null): boolean;
|
|
9
|
+
export declare function interactionUpdateDragSessionCurrentTarget(state: InteractionStateInternal, sq: Square | null): boolean;
|
|
10
|
+
export declare function interactionClear(state: InteractionStateInternal): boolean;
|
|
11
|
+
export declare function interactionClearActive(state: InteractionStateInternal): boolean;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import assert from '@ktarmyshov/assert';
|
|
2
|
+
import { cloneDeep } from 'es-toolkit/object';
|
|
3
|
+
import { setsEqual } from '../../helpers/util';
|
|
4
|
+
import { selectedEqual } from './helpers';
|
|
5
|
+
import { movabilitiesEqual } from './movability';
|
|
6
|
+
export function interactionSetSelected(state, selected) {
|
|
7
|
+
const notChanged = selectedEqual(state.selected, selected);
|
|
8
|
+
if (notChanged)
|
|
9
|
+
return false;
|
|
10
|
+
state.selected = selected ? { ...selected } : null;
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
export function interactionSetMovability(state, m) {
|
|
14
|
+
if (movabilitiesEqual(state.movability, m))
|
|
15
|
+
return false; // no-op
|
|
16
|
+
state.movability = cloneDeep(m); // Defensive copy to prevent external mutations
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
function promotedTosEqual(a, b) {
|
|
20
|
+
if (a === b)
|
|
21
|
+
return true;
|
|
22
|
+
if (a == null || b == null)
|
|
23
|
+
return false;
|
|
24
|
+
return setsEqual(new Set(a), new Set(b));
|
|
25
|
+
}
|
|
26
|
+
function activeDestinationsEqual(a, b) {
|
|
27
|
+
if (a.size !== b.size)
|
|
28
|
+
return false;
|
|
29
|
+
for (const [sq, aDest] of a) {
|
|
30
|
+
const bDest = b.get(sq);
|
|
31
|
+
if (!bDest)
|
|
32
|
+
return false;
|
|
33
|
+
if (aDest.to !== bDest.to ||
|
|
34
|
+
aDest.capturedSquare !== bDest.capturedSquare ||
|
|
35
|
+
aDest.secondary?.from !== bDest.secondary?.from ||
|
|
36
|
+
aDest.secondary?.to !== bDest.secondary?.to ||
|
|
37
|
+
!promotedTosEqual(aDest.promotedTo, bDest.promotedTo))
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
export function interactionSetActiveDestinations(state, dests) {
|
|
43
|
+
if (activeDestinationsEqual(state.activeDestinations, dests))
|
|
44
|
+
return false;
|
|
45
|
+
state.activeDestinations = new Map(dests);
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
export function interactionSetDragSession(state, session) {
|
|
49
|
+
const changed = state.dragSession?.type !== session?.type ||
|
|
50
|
+
state.dragSession?.sourceSquare !== session?.sourceSquare ||
|
|
51
|
+
state.dragSession?.sourcePieceCode !== session?.sourcePieceCode ||
|
|
52
|
+
state.dragSession?.targetSquare !== session?.targetSquare;
|
|
53
|
+
if (!changed)
|
|
54
|
+
return false; // no-op
|
|
55
|
+
state.dragSession = session ? cloneDeep(session) : null;
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
export function interactionUpdateDragSessionCurrentTarget(state, sq) {
|
|
59
|
+
const changed = state.dragSession?.targetSquare !== sq;
|
|
60
|
+
if (!changed)
|
|
61
|
+
return false;
|
|
62
|
+
assert(state.dragSession !== null, 'No active drag session to update target of');
|
|
63
|
+
state.dragSession.targetSquare = sq;
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
export function interactionClear(state) {
|
|
67
|
+
const anySet = state.selected !== null || state.activeDestinations.size > 0 || state.dragSession !== null;
|
|
68
|
+
if (!anySet)
|
|
69
|
+
return false;
|
|
70
|
+
state.selected = null;
|
|
71
|
+
state.activeDestinations = new Map();
|
|
72
|
+
state.dragSession = null;
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
export function interactionClearActive(state) {
|
|
76
|
+
const anyActive = state.dragSession !== null;
|
|
77
|
+
if (!anyActive)
|
|
78
|
+
return false;
|
|
79
|
+
state.dragSession = null;
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { MoveRequestInput, RolePromotionInput, SquareString } from '../../board/types/input';
|
|
2
|
+
export interface MoveDestinationInput extends Omit<MoveRequestInput, 'from' | 'promotedTo'> {
|
|
3
|
+
promotedTo?: RolePromotionInput[];
|
|
4
|
+
}
|
|
5
|
+
export type MovabilityDestinationsRecordInput = Partial<Record<SquareString, readonly MoveDestinationInput[]>>;
|
|
6
|
+
export type MovabilityResolverInput = (source: SquareString) => readonly MoveDestinationInput[] | undefined;
|
|
7
|
+
export type MovabilityDestinationsInput = MovabilityDestinationsRecordInput | MovabilityResolverInput;
|
|
8
|
+
export type StrictMovabilityInput = {
|
|
9
|
+
mode: 'strict';
|
|
10
|
+
destinations: MovabilityDestinationsInput;
|
|
11
|
+
};
|
|
12
|
+
export type FreeMovabilityInput = {
|
|
13
|
+
mode: 'free';
|
|
14
|
+
};
|
|
15
|
+
export type DisabledMovabilityInput = {
|
|
16
|
+
mode: 'disabled';
|
|
17
|
+
};
|
|
18
|
+
export type MovabilityInput = StrictMovabilityInput | FreeMovabilityInput | DisabledMovabilityInput;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ReadonlyDeep } from 'type-fest';
|
|
2
|
+
import type { MoveRequest, PieceCode, RolePromotionCode, Square } from '../../board/types/internal';
|
|
3
|
+
export interface DragSession {
|
|
4
|
+
type: 'lifted-piece-drag' | 'release-targeting';
|
|
5
|
+
sourceSquare: Square;
|
|
6
|
+
sourcePieceCode: PieceCode;
|
|
7
|
+
targetSquare: Square | null;
|
|
8
|
+
}
|
|
9
|
+
export type DragSessionSnapshot = ReadonlyDeep<DragSession>;
|
|
10
|
+
export interface MoveDestination extends Omit<MoveRequest, 'from' | 'promotedTo'> {
|
|
11
|
+
promotedTo?: RolePromotionCode[];
|
|
12
|
+
}
|
|
13
|
+
export type MoveDestinationSnapshot = ReadonlyDeep<MoveDestination>;
|
|
14
|
+
export type MovabilityDestinationsRecord = Partial<Record<Square, readonly MoveDestination[]>>;
|
|
15
|
+
export type MovabilityDestinationsRecordSnapshot = ReadonlyDeep<MovabilityDestinationsRecord>;
|
|
16
|
+
export type MovabilityResolver = (source: Square) => readonly MoveDestination[] | undefined;
|
|
17
|
+
export type MovabilityDestinations = MovabilityDestinationsRecord | MovabilityResolver;
|
|
18
|
+
export type MovabilityDestinationsSnapshot = ReadonlyDeep<MovabilityDestinations>;
|
|
19
|
+
export declare const enum MovabilityModeCode {
|
|
20
|
+
Disabled = 0,
|
|
21
|
+
Free = 1,
|
|
22
|
+
Strict = 2
|
|
23
|
+
}
|
|
24
|
+
export interface MovabilityStrict {
|
|
25
|
+
readonly mode: MovabilityModeCode.Strict;
|
|
26
|
+
readonly destinations: MovabilityDestinationsSnapshot;
|
|
27
|
+
}
|
|
28
|
+
export interface MovabilityFree {
|
|
29
|
+
readonly mode: MovabilityModeCode.Free;
|
|
30
|
+
}
|
|
31
|
+
export interface MovabilityDisabled {
|
|
32
|
+
readonly mode: MovabilityModeCode.Disabled;
|
|
33
|
+
}
|
|
34
|
+
export type Movability = MovabilityStrict | MovabilityFree | MovabilityDisabled;
|
|
35
|
+
export type MovabilitySnapshot = ReadonlyDeep<Movability>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ReadonlyDeep } from 'type-fest';
|
|
2
|
+
import { NonEmptyPieceCode, Square } from '../../board/types/internal';
|
|
3
|
+
import { InteractionStateMutationSession } from '../mutation';
|
|
4
|
+
import { MovabilityInput } from './input';
|
|
5
|
+
import { DragSession, DragSessionSnapshot, Movability, MovabilitySnapshot, MoveDestinationSnapshot } from './internal';
|
|
6
|
+
export interface InteractionStateSelected {
|
|
7
|
+
square: Square;
|
|
8
|
+
pieceCode: NonEmptyPieceCode;
|
|
9
|
+
}
|
|
10
|
+
export interface InteractionStateInternal {
|
|
11
|
+
selected: InteractionStateSelected | null;
|
|
12
|
+
movability: Movability;
|
|
13
|
+
activeDestinations: ReadonlyMap<Square, MoveDestinationSnapshot>;
|
|
14
|
+
dragSession: DragSession | null;
|
|
15
|
+
}
|
|
16
|
+
export type InteractionStateSnapshot = ReadonlyDeep<InteractionStateInternal>;
|
|
17
|
+
export interface InteractionStateInitOptions {
|
|
18
|
+
movability?: MovabilityInput;
|
|
19
|
+
}
|
|
20
|
+
export interface InteractionState {
|
|
21
|
+
readonly selected: InteractionStateSelected | null;
|
|
22
|
+
setSelected(selected: InteractionStateSelected | null, mutationSession: InteractionStateMutationSession): boolean;
|
|
23
|
+
readonly movability: MovabilitySnapshot;
|
|
24
|
+
setMovability(movability: MovabilityInput, mutationSession: InteractionStateMutationSession): boolean;
|
|
25
|
+
readonly activeDestinations: ReadonlyMap<Square, MoveDestinationSnapshot>;
|
|
26
|
+
updateActiveDestinations(mutationSession: InteractionStateMutationSession): boolean;
|
|
27
|
+
readonly dragSession: DragSessionSnapshot | null;
|
|
28
|
+
setDragSession(session: DragSessionSnapshot | null, mutationSession: InteractionStateMutationSession): boolean;
|
|
29
|
+
updateDragSessionCurrentTarget(sq: Square | null, mutationSession: InteractionStateMutationSession): boolean;
|
|
30
|
+
clear(mutationSession: InteractionStateMutationSession): boolean;
|
|
31
|
+
clearActive(mutationSession: InteractionStateMutationSession): boolean;
|
|
32
|
+
getSnapshot(): InteractionStateSnapshot;
|
|
33
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { PositionInput } from './board/types/input';
|
|
2
|
+
import { BoardState, BoardStateSnapshot } from './board/types/main';
|
|
3
|
+
import type { ChangeState, ChangeStateSnapshot } from './change/types';
|
|
4
|
+
import { InteractionState, InteractionStateInitOptions, InteractionStateSnapshot } from './interaction/types/main';
|
|
5
|
+
import { ViewStateSnapshot } from './view/types/internal';
|
|
6
|
+
import { ViewState, ViewStateInitOptions } from './view/types/main';
|
|
7
|
+
export interface RuntimeStateInternal {
|
|
8
|
+
readonly board: BoardState;
|
|
9
|
+
readonly view: ViewState;
|
|
10
|
+
readonly interaction: InteractionState;
|
|
11
|
+
readonly change: ChangeState;
|
|
12
|
+
}
|
|
13
|
+
export interface RuntimeStateSnapshot {
|
|
14
|
+
readonly board: BoardStateSnapshot;
|
|
15
|
+
readonly view: ViewStateSnapshot;
|
|
16
|
+
readonly interaction: InteractionStateSnapshot;
|
|
17
|
+
readonly change: ChangeStateSnapshot;
|
|
18
|
+
}
|
|
19
|
+
export interface RuntimeStateInitOptions {
|
|
20
|
+
board?: PositionInput;
|
|
21
|
+
view?: ViewStateInitOptions;
|
|
22
|
+
interaction?: InteractionStateInitOptions;
|
|
23
|
+
}
|
|
24
|
+
export interface RuntimeState {
|
|
25
|
+
readonly board: BoardState;
|
|
26
|
+
readonly view: ViewState;
|
|
27
|
+
readonly interaction: InteractionState;
|
|
28
|
+
readonly change: ChangeState;
|
|
29
|
+
getSnapshot(): RuntimeStateSnapshot;
|
|
30
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { cloneDeep } from 'es-toolkit/object';
|
|
2
|
+
import { normalizeColor } from '../board/normalize';
|
|
3
|
+
import { viewSetOrientation } from './reducers';
|
|
4
|
+
function createViewStateInternal(opts) {
|
|
5
|
+
const orientation = opts.orientation ? normalizeColor(opts.orientation) : 0 /* ColorCode.White */;
|
|
6
|
+
return {
|
|
7
|
+
orientation
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
export function createViewState(options) {
|
|
11
|
+
const internalState = createViewStateInternal(options);
|
|
12
|
+
return {
|
|
13
|
+
get orientation() {
|
|
14
|
+
return internalState.orientation;
|
|
15
|
+
},
|
|
16
|
+
setOrientation(orientation, mutationSession) {
|
|
17
|
+
const newOrient = normalizeColor(orientation);
|
|
18
|
+
return mutationSession.addMutation('state.view.setOrientation', viewSetOrientation(internalState, newOrient));
|
|
19
|
+
},
|
|
20
|
+
getSnapshot() {
|
|
21
|
+
return cloneDeep(internalState);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ColorInput } from '../../board/types/input';
|
|
2
|
+
import { ColorCode } from '../../board/types/internal';
|
|
3
|
+
import { ViewStateMutationSession } from '../mutation';
|
|
4
|
+
import { ViewStateSnapshot } from './internal';
|
|
5
|
+
export interface ViewStateInitOptions {
|
|
6
|
+
orientation?: ColorInput;
|
|
7
|
+
}
|
|
8
|
+
export interface ViewState {
|
|
9
|
+
readonly orientation: ColorCode;
|
|
10
|
+
setOrientation(orientation: ColorInput, mutationSession: ViewStateMutationSession): boolean;
|
|
11
|
+
getSnapshot(): ViewStateSnapshot;
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { DefaultBuiltinChessboardExtensions } from '../extensions/types/wrapper';
|
|
2
|
+
import { Chessboard, ChessboardExtensionInput, ChessboardInitOptions } from './types';
|
|
3
|
+
export declare function createBoard<TExtensions extends readonly ChessboardExtensionInput[] = DefaultBuiltinChessboardExtensions>(options: ChessboardInitOptions<TExtensions>): Chessboard<TExtensions>;
|