@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.
- package/CHANGELOG.md +16 -0
- package/README.md +224 -47
- package/dist/animation/planner.d.ts +11 -6
- package/dist/animation/planner.js +167 -48
- package/dist/animation/render/fade.d.ts +5 -5
- package/dist/animation/render/fade.js +4 -4
- package/dist/animation/render/move.d.ts +6 -6
- package/dist/animation/render/move.js +6 -6
- package/dist/animation/render/plan.d.ts +6 -6
- package/dist/animation/render/plan.js +3 -3
- package/dist/animation/render/static.d.ts +5 -5
- package/dist/animation/render/static.js +4 -4
- package/dist/animation/render/types.d.ts +1 -1
- package/dist/animation/types.d.ts +15 -16
- package/dist/animation/types.js +1 -6
- package/dist/extensions/animation/factory.d.ts +1 -1
- package/dist/extensions/animation/factory.js +1 -1
- package/dist/extensions/animation/types.d.ts +1 -1
- package/dist/extensions/factory/main.d.ts +1 -1
- package/dist/extensions/factory/main.js +27 -6
- package/dist/extensions/factory/runtime.d.ts +6 -5
- package/dist/extensions/factory/runtime.js +48 -4
- package/dist/extensions/first-party/active-target/factory.d.ts +1 -1
- package/dist/extensions/first-party/active-target/factory.js +9 -9
- package/dist/extensions/first-party/active-target/types.d.ts +2 -2
- package/dist/extensions/first-party/auto-promote/factory.d.ts +2 -0
- package/dist/extensions/first-party/auto-promote/factory.js +51 -0
- package/dist/extensions/first-party/auto-promote/types.d.ts +14 -0
- package/dist/extensions/first-party/auto-promote/types.js +2 -0
- package/dist/extensions/first-party/board-events/factory.d.ts +1 -1
- package/dist/extensions/first-party/board-events/factory.js +3 -16
- package/dist/extensions/first-party/board-events/types.d.ts +6 -7
- package/dist/extensions/first-party/common/helpers.d.ts +2 -2
- package/dist/extensions/first-party/common/helpers.js +1 -1
- package/dist/extensions/first-party/common/types.d.ts +1 -1
- package/dist/extensions/first-party/last-move/factory.d.ts +1 -1
- package/dist/extensions/first-party/last-move/factory.js +10 -10
- package/dist/extensions/first-party/last-move/types.d.ts +2 -2
- package/dist/extensions/first-party/legal-moves/factory.d.ts +1 -1
- package/dist/extensions/first-party/legal-moves/factory.js +7 -7
- package/dist/extensions/first-party/legal-moves/types.d.ts +2 -2
- package/dist/extensions/first-party/main-renderer/animation/factory.d.ts +3 -3
- package/dist/extensions/first-party/main-renderer/animation/factory.js +3 -3
- package/dist/extensions/first-party/main-renderer/animation/render.d.ts +3 -3
- package/dist/extensions/first-party/main-renderer/animation/render.js +2 -3
- package/dist/extensions/first-party/main-renderer/animation/types.d.ts +7 -7
- package/dist/extensions/first-party/main-renderer/animation/update.d.ts +2 -2
- package/dist/extensions/first-party/main-renderer/animation/update.js +12 -26
- package/dist/extensions/first-party/main-renderer/board/factory.d.ts +2 -2
- package/dist/extensions/first-party/main-renderer/board/factory.js +2 -2
- package/dist/extensions/first-party/main-renderer/board/render.d.ts +2 -2
- package/dist/extensions/first-party/main-renderer/board/render.js +6 -6
- package/dist/extensions/first-party/main-renderer/board/types.d.ts +3 -3
- package/dist/extensions/first-party/main-renderer/board/update.d.ts +2 -2
- package/dist/extensions/first-party/main-renderer/board/update.js +8 -6
- package/dist/extensions/first-party/main-renderer/coordinates/factory.d.ts +2 -2
- package/dist/extensions/first-party/main-renderer/coordinates/factory.js +1 -1
- package/dist/extensions/first-party/main-renderer/coordinates/render.d.ts +2 -2
- package/dist/extensions/first-party/main-renderer/coordinates/render.js +7 -7
- package/dist/extensions/first-party/main-renderer/coordinates/types.d.ts +2 -2
- package/dist/extensions/first-party/main-renderer/drag/factory.d.ts +3 -3
- package/dist/extensions/first-party/main-renderer/drag/factory.js +2 -2
- package/dist/extensions/first-party/main-renderer/drag/render.d.ts +2 -2
- package/dist/extensions/first-party/main-renderer/drag/render.js +2 -2
- package/dist/extensions/first-party/main-renderer/drag/types.d.ts +4 -4
- package/dist/extensions/first-party/main-renderer/drag/update.d.ts +2 -2
- package/dist/extensions/first-party/main-renderer/drag/update.js +1 -1
- package/dist/extensions/first-party/main-renderer/factory.d.ts +1 -1
- package/dist/extensions/first-party/main-renderer/factory.js +9 -9
- package/dist/extensions/first-party/main-renderer/normalize.d.ts +2 -3
- package/dist/extensions/first-party/main-renderer/normalize.js +4 -4
- package/dist/extensions/first-party/main-renderer/pieces/factory.d.ts +2 -2
- package/dist/extensions/first-party/main-renderer/pieces/factory.js +2 -2
- package/dist/extensions/first-party/main-renderer/pieces/render.d.ts +2 -2
- package/dist/extensions/first-party/main-renderer/pieces/render.js +9 -9
- package/dist/extensions/first-party/main-renderer/pieces/suppress.d.ts +4 -4
- package/dist/extensions/first-party/main-renderer/pieces/suppress.js +7 -2
- package/dist/extensions/first-party/main-renderer/pieces/types.d.ts +5 -5
- package/dist/extensions/first-party/main-renderer/pieces/update.d.ts +4 -4
- package/dist/extensions/first-party/main-renderer/pieces/update.js +5 -5
- package/dist/extensions/first-party/main-renderer/types/extension.d.ts +3 -3
- package/dist/extensions/first-party/main-renderer/types/extension.js +1 -1
- package/dist/extensions/first-party/main-renderer/types/input.d.ts +2 -2
- package/dist/extensions/first-party/main-renderer/types/instance.d.ts +8 -8
- package/dist/extensions/first-party/main-renderer/types/internal.d.ts +2 -2
- package/dist/extensions/first-party/main-renderer/types/template.d.ts +1 -1
- package/dist/extensions/first-party/promotion/factory.d.ts +3 -0
- package/dist/extensions/first-party/promotion/factory.js +219 -0
- package/dist/extensions/first-party/promotion/normalize.d.ts +3 -0
- package/dist/extensions/first-party/promotion/normalize.js +37 -0
- package/dist/extensions/first-party/promotion/types/input.d.ts +10 -0
- package/dist/extensions/first-party/promotion/types/internal.d.ts +12 -0
- package/dist/extensions/first-party/promotion/types/internal.js +22 -0
- package/dist/extensions/first-party/promotion/types/main.d.ts +24 -0
- package/dist/extensions/first-party/promotion/types/main.js +2 -0
- package/dist/extensions/first-party/selected-square/factory.d.ts +1 -1
- package/dist/extensions/first-party/selected-square/factory.js +7 -7
- package/dist/extensions/first-party/selected-square/types.d.ts +2 -2
- package/dist/extensions/index.d.ts +8 -8
- package/dist/extensions/index.js +6 -6
- package/dist/extensions/invalidation/factory.d.ts +1 -1
- package/dist/extensions/types/basic/events.d.ts +10 -33
- package/dist/extensions/types/basic/events.js +9 -5
- package/dist/extensions/types/basic/interaction.d.ts +21 -0
- package/dist/extensions/types/basic/render.d.ts +2 -2
- package/dist/extensions/types/basic/transient-visuals.d.ts +3 -2
- package/dist/extensions/types/basic/update.d.ts +3 -3
- package/dist/extensions/types/context/animation.d.ts +3 -3
- package/dist/extensions/types/context/events.d.ts +5 -0
- package/dist/extensions/types/context/events.js +1 -0
- package/dist/extensions/types/context/render.d.ts +2 -2
- package/dist/extensions/types/context/transient-visuals.d.ts +2 -2
- package/dist/extensions/types/context/ui-move.d.ts +3 -15
- package/dist/extensions/types/context/update.d.ts +4 -4
- package/dist/extensions/types/context/update.js +1 -1
- package/dist/extensions/types/extension.d.ts +16 -14
- package/dist/extensions/types/main.d.ts +16 -11
- package/dist/extensions/types/surface/commands.d.ts +14 -5
- package/dist/extensions/types/surface/events.d.ts +2 -3
- package/dist/extensions/types/surface/main.d.ts +4 -4
- package/dist/extensions/types/wrapper.d.ts +23 -22
- package/dist/extensions/types/wrapper.js +34 -6
- package/dist/extensions/update.d.ts +3 -3
- package/dist/extensions/update.js +2 -2
- package/dist/index.d.ts +4 -4
- package/dist/index.js +1 -1
- package/dist/layout/factory.d.ts +1 -1
- package/dist/layout/factory.js +4 -4
- package/dist/layout/geometry/factory.d.ts +3 -12
- package/dist/layout/geometry/factory.js +17 -18
- package/dist/layout/geometry/helpers.d.ts +5 -0
- package/dist/layout/geometry/helpers.js +33 -0
- package/dist/layout/geometry/types.d.ts +14 -13
- package/dist/layout/helpers.d.ts +3 -4
- package/dist/layout/helpers.js +5 -5
- package/dist/layout/mutation.d.ts +1 -1
- package/dist/layout/reducers.d.ts +1 -1
- package/dist/layout/reducers.js +10 -9
- package/dist/layout/types.d.ts +7 -7
- package/dist/mutation/pipeline.d.ts +1 -1
- package/dist/mutation/pipeline.js +1 -1
- package/dist/mutation/session.d.ts +1 -1
- package/dist/render/factory.d.ts +1 -1
- package/dist/render/factory.js +7 -7
- package/dist/render/mount.d.ts +1 -1
- package/dist/render/mount.js +4 -4
- package/dist/render/rendering/animation.d.ts +1 -1
- package/dist/render/rendering/animation.js +1 -1
- package/dist/render/rendering/helpers.d.ts +1 -1
- package/dist/render/rendering/state.d.ts +2 -2
- package/dist/render/rendering/state.js +9 -9
- package/dist/render/rendering/visuals.d.ts +2 -2
- package/dist/render/rendering/visuals.js +1 -1
- package/dist/render/scheduler/scheduler.d.ts +1 -1
- package/dist/render/svg/factory.d.ts +2 -2
- package/dist/render/svg/factory.js +1 -1
- package/dist/render/svg/helpers.d.ts +1 -1
- package/dist/render/svg/helpers.js +1 -1
- package/dist/render/types.d.ts +5 -5
- package/dist/runtime/factory/events.d.ts +3 -0
- package/dist/runtime/factory/events.js +18 -0
- package/dist/runtime/factory/helpers.d.ts +2 -2
- package/dist/runtime/factory/helpers.js +14 -14
- package/dist/runtime/factory/input.d.ts +2 -2
- package/dist/runtime/factory/input.js +20 -13
- package/dist/runtime/factory/main.d.ts +1 -1
- package/dist/runtime/factory/main.js +56 -16
- package/dist/runtime/input/adapter/event.d.ts +3 -0
- package/dist/runtime/input/adapter/event.js +19 -0
- package/dist/runtime/input/adapter/factory.d.ts +1 -1
- package/dist/runtime/input/adapter/factory.js +19 -38
- package/dist/runtime/input/adapter/helpers.d.ts +3 -5
- package/dist/runtime/input/adapter/helpers.js +60 -12
- package/dist/runtime/input/adapter/pointer.d.ts +7 -11
- package/dist/runtime/input/adapter/pointer.js +37 -70
- package/dist/runtime/input/adapter/types.d.ts +7 -4
- package/dist/runtime/input/adapter/types.js +6 -1
- package/dist/runtime/input/controller/factory.d.ts +1 -1
- package/dist/runtime/input/controller/factory.js +13 -12
- package/dist/runtime/input/controller/helpers.d.ts +2 -2
- package/dist/runtime/input/controller/pointer.d.ts +6 -7
- package/dist/runtime/input/controller/pointer.js +39 -38
- package/dist/runtime/input/controller/transient-visuals.d.ts +3 -3
- package/dist/runtime/input/controller/transient-visuals.js +12 -5
- package/dist/runtime/input/controller/types.d.ts +8 -7
- package/dist/runtime/layout.d.ts +1 -1
- package/dist/runtime/layout.js +2 -2
- package/dist/runtime/lifecycle.d.ts +2 -2
- package/dist/runtime/lifecycle.js +8 -8
- package/dist/runtime/mutation/extension-update.d.ts +1 -1
- package/dist/runtime/mutation/factory.d.ts +1 -1
- package/dist/runtime/mutation/factory.js +6 -6
- package/dist/runtime/mutation/interaction.d.ts +1 -1
- package/dist/runtime/mutation/interaction.js +3 -7
- package/dist/runtime/mutation/invalidation.d.ts +1 -0
- package/dist/runtime/mutation/invalidation.js +1 -1
- package/dist/runtime/mutation/last-move.d.ts +1 -1
- package/dist/runtime/mutation/layout.d.ts +1 -1
- package/dist/runtime/mutation/pipeline.d.ts +6 -6
- package/dist/runtime/mutation/request-render.d.ts +1 -1
- package/dist/runtime/mutation/request-render.js +1 -1
- package/dist/runtime/mutation/run.d.ts +1 -1
- package/dist/runtime/mutation/types.d.ts +10 -8
- package/dist/runtime/types/main.d.ts +8 -6
- package/dist/state/board/check.d.ts +3 -3
- package/dist/state/board/check.js +1 -1
- package/dist/state/board/coords.d.ts +1 -1
- package/dist/state/board/denormalize.d.ts +3 -3
- package/dist/state/board/denormalize.js +4 -4
- package/dist/state/board/factory.d.ts +2 -2
- package/dist/state/board/factory.js +4 -4
- package/dist/state/board/mutation.d.ts +2 -2
- package/dist/state/board/normalize.d.ts +2 -2
- package/dist/state/board/normalize.js +2 -2
- package/dist/state/board/piece.d.ts +1 -1
- package/dist/state/board/position.d.ts +2 -2
- package/dist/state/board/position.js +2 -2
- package/dist/state/board/reducers.d.ts +2 -2
- package/dist/state/board/reducers.js +3 -3
- package/dist/state/board/types/input.d.ts +1 -1
- package/dist/state/board/types/internal.d.ts +1 -1
- package/dist/state/board/types/main.d.ts +3 -3
- package/dist/state/board/types/output.d.ts +2 -2
- package/dist/state/change/{factory.d.ts → factory/main.d.ts} +1 -1
- package/dist/state/change/{factory.js → factory/main.js} +8 -5
- package/dist/state/change/factory/ui-move.d.ts +4 -0
- package/dist/{runtime → state/change}/factory/ui-move.js +9 -9
- package/dist/state/change/helpers.d.ts +6 -4
- package/dist/state/change/helpers.js +12 -2
- package/dist/state/change/mutation.d.ts +2 -2
- package/dist/state/change/reducers.d.ts +4 -4
- package/dist/state/change/reducers.js +4 -4
- package/dist/state/change/types/main.d.ts +18 -0
- package/dist/state/change/types/main.js +1 -0
- package/dist/state/change/types/ui-move.d.ts +25 -0
- package/dist/state/change/types/ui-move.js +1 -0
- package/dist/state/factory.d.ts +1 -1
- package/dist/state/factory.js +4 -4
- package/dist/state/interaction/factory.d.ts +1 -1
- package/dist/state/interaction/factory.js +7 -5
- package/dist/state/interaction/helpers.d.ts +4 -2
- package/dist/state/interaction/helpers.js +5 -2
- package/dist/state/interaction/movability.d.ts +3 -3
- package/dist/state/interaction/movability.js +2 -2
- package/dist/state/interaction/mutation.d.ts +1 -1
- package/dist/state/interaction/normalize.d.ts +2 -2
- package/dist/state/interaction/normalize.js +2 -2
- package/dist/state/interaction/reducers.d.ts +3 -3
- package/dist/state/interaction/reducers.js +3 -3
- package/dist/state/interaction/types/input.d.ts +1 -1
- package/dist/state/interaction/types/internal.d.ts +10 -2
- package/dist/state/interaction/types/main.d.ts +4 -4
- package/dist/state/types.d.ts +6 -6
- package/dist/state/view/factory.d.ts +1 -1
- package/dist/state/view/factory.js +2 -2
- package/dist/state/view/mutation.d.ts +1 -1
- package/dist/state/view/reducers.d.ts +2 -2
- package/dist/state/view/types/internal.d.ts +1 -1
- package/dist/state/view/types/main.d.ts +4 -4
- package/dist/wrapper/factory.d.ts +2 -2
- package/dist/wrapper/factory.js +3 -27
- package/dist/wrapper/types.d.ts +4 -4
- package/package.json +9 -5
- package/dist/runtime/factory/ui-move.d.ts +0 -4
- package/dist/runtime/types/ui-move.d.ts +0 -9
- package/dist/state/change/types.d.ts +0 -17
- /package/dist/{runtime/types/ui-move.js → extensions/first-party/promotion/types/input.js} +0 -0
- /package/dist/{state/change/types.js → extensions/types/basic/interaction.js} +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import assert from '@ktarmyshov/assert';
|
|
2
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';
|
|
3
|
+
import { updateActiveDestinations } from './helpers.js';
|
|
4
|
+
import { normalizeMovability } from './normalize.js';
|
|
5
|
+
import { interactionClear, interactionClearActive, interactionSetDragSession, interactionSetMovability, interactionSetSelected, interactionUpdateDragSessionCurrentTarget } from './reducers.js';
|
|
6
6
|
const DefaultMovabilityDisabled = { mode: 0 /* MovabilityModeCode.Disabled */ };
|
|
7
7
|
/**
|
|
8
8
|
* Create a fresh interaction state with all fields set to null or false.
|
|
@@ -51,8 +51,10 @@ export function createInteractionState(options) {
|
|
|
51
51
|
return internalState.dragSession ? { ...internalState.dragSession } : null;
|
|
52
52
|
},
|
|
53
53
|
setDragSession(session, mutationSession) {
|
|
54
|
-
//
|
|
55
|
-
|
|
54
|
+
// assert that there is no active session when setting a new session.
|
|
55
|
+
assert(session === null || internalState.dragSession === null, 'Cannot set a new drag session while another session is active');
|
|
56
|
+
if (session && session.owner === 'core') {
|
|
57
|
+
// Assert that the selected is the same as the source of the drag session when setting a lifted-piece-drag session
|
|
56
58
|
assert(internalState.selected, 'There must be a selected piece to start a drag session');
|
|
57
59
|
if (session.type === 'lifted-piece-drag') {
|
|
58
60
|
assert(internalState.selected, 'There must be a selected piece to start a lifted-piece-drag session');
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { InteractionStateMutationSession } from './mutation';
|
|
2
|
-
import {
|
|
1
|
+
import { InteractionStateMutationSession } from './mutation.js';
|
|
2
|
+
import { DragSessionCoreOwnedSnapshot, DragSessionSnapshot } from './types/internal.js';
|
|
3
|
+
import { InteractionStateInternal, InteractionStateSelected } from './types/main.js';
|
|
3
4
|
export declare function selectedEqual(a: InteractionStateSelected | null, b: InteractionStateSelected | null): boolean;
|
|
4
5
|
export declare function updateActiveDestinations(state: InteractionStateInternal, mutationSession: InteractionStateMutationSession): boolean;
|
|
6
|
+
export declare function isDragSessionCoreOwned(session: DragSessionSnapshot): session is DragSessionCoreOwnedSnapshot;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { getActiveDestinations } from './movability';
|
|
2
|
-
import { interactionSetActiveDestinations } from './reducers';
|
|
1
|
+
import { getActiveDestinations } from './movability.js';
|
|
2
|
+
import { interactionSetActiveDestinations } from './reducers.js';
|
|
3
3
|
export function selectedEqual(a, b) {
|
|
4
4
|
if (a === b)
|
|
5
5
|
return true;
|
|
@@ -14,3 +14,6 @@ export function updateActiveDestinations(state, mutationSession) {
|
|
|
14
14
|
const activeDests = getActiveDestinations(state, state.selected.square);
|
|
15
15
|
return mutationSession.addMutation('state.interaction.updateActiveDestinations', interactionSetActiveDestinations(state, activeDests));
|
|
16
16
|
}
|
|
17
|
+
export function isDragSessionCoreOwned(session) {
|
|
18
|
+
return session.owner === 'core';
|
|
19
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Square } from '../board/types/internal';
|
|
2
|
-
import { MoveDestinationSnapshot, type MovabilitySnapshot } from './types/internal';
|
|
3
|
-
import { InteractionStateInternal } from './types/main';
|
|
1
|
+
import type { Square } from '../board/types/internal.js';
|
|
2
|
+
import { MoveDestinationSnapshot, type MovabilitySnapshot } from './types/internal.js';
|
|
3
|
+
import { InteractionStateInternal } from './types/main.js';
|
|
4
4
|
export declare function movabilitiesEqual(a: MovabilitySnapshot, b: MovabilitySnapshot): boolean;
|
|
5
5
|
export declare function getActiveDestinations(state: InteractionStateInternal, from: Square): ReadonlyMap<Square, MoveDestinationSnapshot>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { setsEqual } from '../../helpers/util';
|
|
2
|
-
import { assertValidSquare } from '../board/check';
|
|
1
|
+
import { setsEqual } from '../../helpers/util.js';
|
|
2
|
+
import { assertValidSquare } from '../board/check.js';
|
|
3
3
|
function moveDestinationsEqual(a, b) {
|
|
4
4
|
if (a === b)
|
|
5
5
|
return true;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { MutationSession } from '../../mutation/types';
|
|
1
|
+
import type { MutationSession } from '../../mutation/types.js';
|
|
2
2
|
export type InteractionStateMutationPayloadByCause = {
|
|
3
3
|
'state.interaction.setSelectedSquare': undefined;
|
|
4
4
|
'state.interaction.setDragSession': undefined;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ReadonlyDeep } from 'type-fest';
|
|
2
|
-
import { MovabilityInput, MoveDestinationInput } from './types/input';
|
|
3
|
-
import { Movability, MoveDestination } from './types/internal';
|
|
2
|
+
import { MovabilityInput, MoveDestinationInput } from './types/input.js';
|
|
3
|
+
import { Movability, MoveDestination } from './types/internal.js';
|
|
4
4
|
export declare function normalizeMoveDestinationInput(destination: ReadonlyDeep<MoveDestinationInput>): MoveDestination;
|
|
5
5
|
export declare function normalizeMovability(movability: MovabilityInput): Movability;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { denormalizeSquare } from '../board/denormalize';
|
|
2
|
-
import { normalizeRolePromotion, normalizeSquare } from '../board/normalize';
|
|
1
|
+
import { denormalizeSquare } from '../board/denormalize.js';
|
|
2
|
+
import { normalizeRolePromotion, normalizeSquare } from '../board/normalize.js';
|
|
3
3
|
export function normalizeMoveDestinationInput(destination) {
|
|
4
4
|
return {
|
|
5
5
|
to: normalizeSquare(destination.to),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
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';
|
|
2
|
+
import type { Square } from '../board/types/internal.js';
|
|
3
|
+
import { Movability, type DragSessionSnapshot, type MoveDestination } from './types/internal.js';
|
|
4
|
+
import { InteractionStateInternal, InteractionStateSelected } from './types/main.js';
|
|
5
5
|
export declare function interactionSetSelected(state: InteractionStateInternal, selected: InteractionStateSelected | null): boolean;
|
|
6
6
|
export declare function interactionSetMovability(state: InteractionStateInternal, m: Movability): boolean;
|
|
7
7
|
export declare function interactionSetActiveDestinations(state: InteractionStateInternal, dests: ReadonlyMap<Square, ReadonlyDeep<MoveDestination>>): boolean;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import assert from '@ktarmyshov/assert';
|
|
2
2
|
import { cloneDeep } from 'es-toolkit/object';
|
|
3
|
-
import { setsEqual } from '../../helpers/util';
|
|
4
|
-
import { selectedEqual } from './helpers';
|
|
5
|
-
import { movabilitiesEqual } from './movability';
|
|
3
|
+
import { setsEqual } from '../../helpers/util.js';
|
|
4
|
+
import { selectedEqual } from './helpers.js';
|
|
5
|
+
import { movabilitiesEqual } from './movability.js';
|
|
6
6
|
export function interactionSetSelected(state, selected) {
|
|
7
7
|
const notChanged = selectedEqual(state.selected, selected);
|
|
8
8
|
if (notChanged)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MoveRequestInput, RolePromotionInput, SquareString } from '../../board/types/input';
|
|
1
|
+
import { MoveRequestInput, RolePromotionInput, SquareString } from '../../board/types/input.js';
|
|
2
2
|
export interface MoveDestinationInput extends Omit<MoveRequestInput, 'from' | 'promotedTo'> {
|
|
3
3
|
promotedTo?: RolePromotionInput[];
|
|
4
4
|
}
|
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
import type { ReadonlyDeep } from 'type-fest';
|
|
2
|
-
import type {
|
|
3
|
-
|
|
2
|
+
import type { ExtensionDragSession, ExtensionDragSessionBase } from '../../../extensions/types/basic/interaction.js';
|
|
3
|
+
import type { MoveRequest, PieceCode, RolePromotionCode, Square } from '../../board/types/internal.js';
|
|
4
|
+
export type DragSessionExtensionOwned = ExtensionDragSession & {
|
|
5
|
+
owner: string;
|
|
6
|
+
};
|
|
7
|
+
export type DragSessionExtensionOwnedSnapshot = ReadonlyDeep<DragSessionExtensionOwned>;
|
|
8
|
+
export interface DragSessionCoreOwned extends ExtensionDragSessionBase {
|
|
9
|
+
owner: 'core';
|
|
4
10
|
type: 'lifted-piece-drag' | 'release-targeting';
|
|
5
11
|
sourceSquare: Square;
|
|
6
12
|
sourcePieceCode: PieceCode;
|
|
7
13
|
targetSquare: Square | null;
|
|
8
14
|
}
|
|
15
|
+
export type DragSessionCoreOwnedSnapshot = ReadonlyDeep<DragSessionCoreOwned>;
|
|
16
|
+
export type DragSession = DragSessionCoreOwned | DragSessionExtensionOwned;
|
|
9
17
|
export type DragSessionSnapshot = ReadonlyDeep<DragSession>;
|
|
10
18
|
export interface MoveDestination extends Omit<MoveRequest, 'from' | 'promotedTo'> {
|
|
11
19
|
promotedTo?: RolePromotionCode[];
|
|
@@ -1,8 +1,8 @@
|
|
|
1
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';
|
|
2
|
+
import { NonEmptyPieceCode, Square } from '../../board/types/internal.js';
|
|
3
|
+
import { InteractionStateMutationSession } from '../mutation.js';
|
|
4
|
+
import { MovabilityInput } from './input.js';
|
|
5
|
+
import { DragSession, DragSessionSnapshot, Movability, MovabilitySnapshot, MoveDestinationSnapshot } from './internal.js';
|
|
6
6
|
export interface InteractionStateSelected {
|
|
7
7
|
square: Square;
|
|
8
8
|
pieceCode: NonEmptyPieceCode;
|
package/dist/state/types.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
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';
|
|
1
|
+
import { PositionInput } from './board/types/input.js';
|
|
2
|
+
import { BoardState, BoardStateSnapshot } from './board/types/main.js';
|
|
3
|
+
import type { ChangeState, ChangeStateSnapshot } from './change/types/main.js';
|
|
4
|
+
import { InteractionState, InteractionStateInitOptions, InteractionStateSnapshot } from './interaction/types/main.js';
|
|
5
|
+
import { ViewStateSnapshot } from './view/types/internal.js';
|
|
6
|
+
import { ViewState, ViewStateInitOptions } from './view/types/main.js';
|
|
7
7
|
export interface RuntimeStateInternal {
|
|
8
8
|
readonly board: BoardState;
|
|
9
9
|
readonly view: ViewState;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { ViewState, ViewStateInitOptions } from './types/main';
|
|
1
|
+
import { ViewState, ViewStateInitOptions } from './types/main.js';
|
|
2
2
|
export declare function createViewState(options: ViewStateInitOptions): ViewState;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { cloneDeep } from 'es-toolkit/object';
|
|
2
|
-
import { normalizeColor } from '../board/normalize';
|
|
3
|
-
import { viewSetOrientation } from './reducers';
|
|
2
|
+
import { normalizeColor } from '../board/normalize.js';
|
|
3
|
+
import { viewSetOrientation } from './reducers.js';
|
|
4
4
|
function createViewStateInternal(opts) {
|
|
5
5
|
const orientation = opts.orientation ? normalizeColor(opts.orientation) : 0 /* ColorCode.White */;
|
|
6
6
|
return {
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { ColorCode } from '../board/types/internal';
|
|
2
|
-
import type { ViewStateInternal } from './types/internal';
|
|
1
|
+
import { ColorCode } from '../board/types/internal.js';
|
|
2
|
+
import type { ViewStateInternal } from './types/internal.js';
|
|
3
3
|
export declare function viewSetOrientation(state: ViewStateInternal, orientation: ColorCode): boolean;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ColorInput } from '../../board/types/input';
|
|
2
|
-
import { ColorCode } from '../../board/types/internal';
|
|
3
|
-
import { ViewStateMutationSession } from '../mutation';
|
|
4
|
-
import { ViewStateSnapshot } from './internal';
|
|
1
|
+
import { ColorInput } from '../../board/types/input.js';
|
|
2
|
+
import { ColorCode } from '../../board/types/internal.js';
|
|
3
|
+
import { ViewStateMutationSession } from '../mutation.js';
|
|
4
|
+
import { ViewStateSnapshot } from './internal.js';
|
|
5
5
|
export interface ViewStateInitOptions {
|
|
6
6
|
orientation?: ColorInput;
|
|
7
7
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { DefaultBuiltinChessboardExtensions } from '../extensions/types/wrapper';
|
|
2
|
-
import { Chessboard, ChessboardExtensionInput, ChessboardInitOptions } from './types';
|
|
1
|
+
import { DefaultBuiltinChessboardExtensions } from '../extensions/types/wrapper.js';
|
|
2
|
+
import { Chessboard, ChessboardExtensionInput, ChessboardInitOptions } from './types.js';
|
|
3
3
|
export declare function createBoard<TExtensions extends readonly ChessboardExtensionInput[] = DefaultBuiltinChessboardExtensions>(options: ChessboardInitOptions<TExtensions>): Chessboard<TExtensions>;
|
package/dist/wrapper/factory.js
CHANGED
|
@@ -1,36 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { createLastMove } from '../extensions/first-party/last-move/factory';
|
|
4
|
-
import { createLegalMoves } from '../extensions/first-party/legal-moves/factory';
|
|
5
|
-
import { createMainRenderer } from '../extensions/first-party/main-renderer/factory';
|
|
6
|
-
import { createSelectedSquare } from '../extensions/first-party/selected-square/factory';
|
|
7
|
-
import { DefaultBuiltinChessboardExtensions } from '../extensions/types/wrapper';
|
|
8
|
-
import { createRuntime } from '../runtime/factory/main';
|
|
9
|
-
function createBuiltInExtensionDefinition(id) {
|
|
10
|
-
switch (id) {
|
|
11
|
-
case 'mainRenderer':
|
|
12
|
-
return createMainRenderer();
|
|
13
|
-
case 'events':
|
|
14
|
-
return createBoardEvents();
|
|
15
|
-
case 'selectedSquare':
|
|
16
|
-
return createSelectedSquare();
|
|
17
|
-
case 'activeTarget':
|
|
18
|
-
return createActiveTarget();
|
|
19
|
-
case 'legalMoves':
|
|
20
|
-
return createLegalMoves();
|
|
21
|
-
case 'lastMove':
|
|
22
|
-
return createLastMove();
|
|
23
|
-
default:
|
|
24
|
-
throw new Error(`Unknown built-in extension id: ${id}`);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
1
|
+
import { builtInExtensionFactoryMap, DefaultBuiltinChessboardExtensions } from '../extensions/types/wrapper.js';
|
|
2
|
+
import { createRuntime } from '../runtime/factory/main.js';
|
|
27
3
|
export function createBoard(options) {
|
|
28
4
|
// prepare init options for runtime
|
|
29
5
|
const extensionsInput = options.extensions ?? DefaultBuiltinChessboardExtensions;
|
|
30
6
|
const extensions = extensionsInput.map((ext) => {
|
|
31
7
|
if (typeof ext === 'string') {
|
|
32
8
|
// built-in extension, convert to definition
|
|
33
|
-
return
|
|
9
|
+
return builtInExtensionFactoryMap[ext]();
|
|
34
10
|
}
|
|
35
11
|
// assume it's already a definition
|
|
36
12
|
return ext;
|
package/dist/wrapper/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { AnyExtensionDefinition, ExtensionDefinitionId, ExtensionDefinitionPublicApi } from '../extensions/types/extension';
|
|
2
|
-
import { BuiltInExtensionDefinitionMap, BuiltInExtensionId, DefaultBuiltinChessboardExtensions } from '../extensions/types/wrapper';
|
|
3
|
-
import { Runtime } from '../runtime/types/main';
|
|
4
|
-
import { RuntimeStateInitOptions } from '../state/types';
|
|
1
|
+
import type { AnyExtensionDefinition, ExtensionDefinitionId, ExtensionDefinitionPublicApi } from '../extensions/types/extension.js';
|
|
2
|
+
import { BuiltInExtensionDefinitionMap, BuiltInExtensionId, DefaultBuiltinChessboardExtensions } from '../extensions/types/wrapper.js';
|
|
3
|
+
import { Runtime } from '../runtime/types/main.js';
|
|
4
|
+
import { RuntimeStateInitOptions } from '../state/types.js';
|
|
5
5
|
/**
|
|
6
6
|
* What createBoard accepts in options.extensions
|
|
7
7
|
*/
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mirasen/chessboard",
|
|
3
|
-
"description": "
|
|
4
|
-
"version": "0.
|
|
3
|
+
"description": "Framework-agnostic TypeScript chessboard platform with real chess interaction built in.",
|
|
4
|
+
"version": "1.0.0-rc.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Mirasen",
|
|
@@ -10,10 +10,14 @@
|
|
|
10
10
|
"keywords": [
|
|
11
11
|
"mirasen",
|
|
12
12
|
"chessboard",
|
|
13
|
-
"chess-ui",
|
|
14
13
|
"chess",
|
|
14
|
+
"chess-ui",
|
|
15
|
+
"chessboard-ui",
|
|
16
|
+
"typescript",
|
|
17
|
+
"framework-agnostic",
|
|
15
18
|
"svg",
|
|
16
|
-
"
|
|
19
|
+
"extensions",
|
|
20
|
+
"chessboard-platform"
|
|
17
21
|
],
|
|
18
22
|
"homepage": "https://mirasen.io/chessboard",
|
|
19
23
|
"repository": {
|
|
@@ -52,7 +56,7 @@
|
|
|
52
56
|
"test-backup": "npm run check:test && vitest run --run",
|
|
53
57
|
"coverage": "echo 'No tests for now...'",
|
|
54
58
|
"coverage-backup": "vitest run --coverage",
|
|
55
|
-
"changeset:version": "changeset version && npm install && git add --all",
|
|
59
|
+
"changeset:version": "changeset version && npm install && npm run format && git add --all",
|
|
56
60
|
"changeset:publish": "changeset publish"
|
|
57
61
|
},
|
|
58
62
|
"files": [
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { ExtensionUIMoveRequestContext } from '../../extensions/types/context/ui-move';
|
|
2
|
-
import { Square } from '../../state/board/types/internal';
|
|
3
|
-
import { MoveDestinationSnapshot } from '../../state/interaction/types/internal';
|
|
4
|
-
export declare function createUIMoveRequestContext(sourceSquare: Square, destination: MoveDestinationSnapshot): ExtensionUIMoveRequestContext;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { ExtensionUIMoveRequestStatus } from '../../extensions/types/context/ui-move';
|
|
2
|
-
import { MoveRequest, Square } from '../../state/board/types/internal';
|
|
3
|
-
import { MoveDestinationSnapshot } from '../../state/interaction/types/internal';
|
|
4
|
-
export interface UIMoveRequestContextInternal {
|
|
5
|
-
readonly sourceSquare: Square;
|
|
6
|
-
readonly destination: MoveDestinationSnapshot;
|
|
7
|
-
status: ExtensionUIMoveRequestStatus;
|
|
8
|
-
resolvedMoveRequest: MoveRequest | null;
|
|
9
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { ReadonlyDeep } from 'type-fest';
|
|
2
|
-
import { ExtensionUIMoveRequestContext, ExtensionUIMoveRequestContextSnapshot } from '../../extensions/types/context/ui-move';
|
|
3
|
-
import type { MoveSnapshot } from '../board/types/internal';
|
|
4
|
-
import type { ChangeStateMutationSession } from './mutation';
|
|
5
|
-
export interface ChangeStateInternal {
|
|
6
|
-
lastMove: MoveSnapshot | null;
|
|
7
|
-
deferredUIMoveRequestContext: ExtensionUIMoveRequestContext | null;
|
|
8
|
-
}
|
|
9
|
-
export type ChangeStateSnapshot = ReadonlyDeep<Omit<ChangeStateInternal, 'deferredUIMoveRequestContext'>> & {
|
|
10
|
-
deferredUIMoveRequestContext: ExtensionUIMoveRequestContextSnapshot | null;
|
|
11
|
-
};
|
|
12
|
-
export interface ChangeState {
|
|
13
|
-
readonly lastMove: MoveSnapshot | null;
|
|
14
|
-
setLastMove(move: MoveSnapshot | null, mutationSession: ChangeStateMutationSession): boolean;
|
|
15
|
-
setDeferredUIMoveRequestContext(context: ExtensionUIMoveRequestContext, mutationSession: ChangeStateMutationSession): boolean;
|
|
16
|
-
getSnapshot(): ChangeStateSnapshot;
|
|
17
|
-
}
|
|
File without changes
|
|
File without changes
|