@mirasen/chessboard 1.1.5 → 1.2.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 +37 -0
- package/README.md +1 -1
- package/dist/animation/render/fade.d.ts +2 -3
- package/dist/animation/render/fade.js +6 -6
- package/dist/animation/render/move.d.ts +2 -3
- package/dist/animation/render/move.js +6 -6
- package/dist/animation/render/plan.d.ts +3 -4
- package/dist/animation/render/plan.js +5 -5
- package/dist/animation/render/static.d.ts +2 -3
- package/dist/animation/render/static.js +4 -4
- package/dist/animation/render/types.d.ts +10 -4
- package/dist/extensions/build/index.d.ts +1 -2
- package/dist/extensions/build/index.js +1 -1
- package/dist/extensions/factory/main.js +11 -7
- package/dist/extensions/factory/runtime.js +24 -1
- package/dist/extensions/first-party/active-target/factory.js +18 -11
- package/dist/extensions/first-party/annotations/api.d.ts +16 -0
- package/dist/extensions/first-party/annotations/api.js +79 -0
- package/dist/extensions/first-party/annotations/committed.d.ts +3 -0
- package/dist/extensions/first-party/annotations/committed.js +11 -0
- package/dist/extensions/first-party/annotations/constants.d.ts +3 -0
- package/dist/extensions/first-party/annotations/constants.js +54 -0
- package/dist/extensions/first-party/annotations/denormalize.d.ts +4 -0
- package/dist/extensions/first-party/annotations/denormalize.js +22 -0
- package/dist/extensions/first-party/annotations/factory.d.ts +3 -0
- package/dist/extensions/first-party/annotations/factory.js +143 -0
- package/dist/extensions/first-party/annotations/interaction.d.ts +8 -0
- package/dist/extensions/first-party/annotations/interaction.js +129 -0
- package/dist/extensions/first-party/annotations/invalidation.d.ts +3 -0
- package/dist/extensions/first-party/annotations/invalidation.js +7 -0
- package/dist/extensions/first-party/annotations/normalize.d.ts +12 -0
- package/dist/extensions/first-party/annotations/normalize.js +54 -0
- package/dist/extensions/first-party/annotations/render/committed.d.ts +3 -0
- package/dist/extensions/first-party/annotations/render/committed.js +123 -0
- package/dist/extensions/first-party/annotations/render/helpers/arrows.d.ts +33 -0
- package/dist/extensions/first-party/annotations/render/helpers/arrows.js +93 -0
- package/dist/extensions/first-party/annotations/render/helpers/circles.d.ts +18 -0
- package/dist/extensions/first-party/annotations/render/helpers/circles.js +30 -0
- package/dist/extensions/first-party/annotations/render/preview.d.ts +3 -0
- package/dist/extensions/first-party/annotations/render/preview.js +96 -0
- package/dist/extensions/first-party/annotations/types/internal.d.ts +77 -0
- package/dist/extensions/first-party/annotations/types/internal.js +1 -0
- package/dist/extensions/first-party/annotations/types/main.d.ts +40 -0
- package/dist/extensions/first-party/annotations/types/main.js +6 -0
- package/dist/extensions/first-party/annotations/types/public.d.ts +48 -0
- package/dist/extensions/first-party/annotations/types/public.js +1 -0
- package/dist/extensions/first-party/annotations/update.d.ts +3 -0
- package/dist/extensions/first-party/annotations/update.js +45 -0
- package/dist/extensions/first-party/auto-promote/factory.js +6 -6
- package/dist/extensions/first-party/board-events/factory.js +6 -6
- package/dist/extensions/first-party/common/helpers.d.ts +2 -1
- package/dist/extensions/first-party/common/helpers.js +6 -5
- package/dist/extensions/first-party/common/types.d.ts +2 -0
- package/dist/extensions/first-party/last-move/factory.js +9 -9
- package/dist/extensions/first-party/legal-moves/factory.js +8 -8
- package/dist/extensions/first-party/main-renderer/animation/factory.d.ts +2 -2
- package/dist/extensions/first-party/main-renderer/animation/factory.js +4 -4
- package/dist/extensions/first-party/main-renderer/animation/render.d.ts +1 -1
- package/dist/extensions/first-party/main-renderer/animation/render.js +2 -2
- package/dist/extensions/first-party/main-renderer/animation/types.d.ts +3 -3
- package/dist/extensions/first-party/main-renderer/board/factory.js +2 -2
- package/dist/extensions/first-party/main-renderer/board/render.d.ts +1 -1
- package/dist/extensions/first-party/main-renderer/board/render.js +4 -4
- package/dist/extensions/first-party/main-renderer/board/types.d.ts +1 -1
- package/dist/extensions/first-party/main-renderer/coordinates/factory.js +2 -2
- package/dist/extensions/first-party/main-renderer/coordinates/render.d.ts +1 -1
- package/dist/extensions/first-party/main-renderer/coordinates/render.js +5 -5
- package/dist/extensions/first-party/main-renderer/coordinates/types.d.ts +1 -1
- package/dist/extensions/first-party/main-renderer/drag/factory.d.ts +2 -2
- package/dist/extensions/first-party/main-renderer/drag/factory.js +11 -8
- package/dist/extensions/first-party/main-renderer/drag/render.d.ts +1 -1
- package/dist/extensions/first-party/main-renderer/drag/render.js +7 -6
- package/dist/extensions/first-party/main-renderer/drag/types.d.ts +6 -5
- package/dist/extensions/first-party/main-renderer/drag/update.js +2 -2
- package/dist/extensions/first-party/main-renderer/factory.js +9 -5
- package/dist/extensions/first-party/main-renderer/piece-symbols.d.ts +19 -0
- package/dist/extensions/first-party/main-renderer/piece-symbols.js +45 -0
- package/dist/extensions/first-party/main-renderer/pieces/factory.d.ts +2 -2
- package/dist/extensions/first-party/main-renderer/pieces/factory.js +4 -4
- package/dist/extensions/first-party/main-renderer/pieces/render.d.ts +1 -1
- package/dist/extensions/first-party/main-renderer/pieces/render.js +8 -8
- package/dist/extensions/first-party/main-renderer/pieces/types.d.ts +4 -4
- package/dist/extensions/first-party/main-renderer/types/extension.d.ts +1 -1
- package/dist/extensions/first-party/main-renderer/types/extension.js +8 -1
- package/dist/extensions/first-party/main-renderer/types/instance.d.ts +2 -0
- package/dist/extensions/first-party/promotion/factory.js +10 -10
- package/dist/extensions/first-party/selected-square/factory.js +8 -8
- package/dist/extensions/first-party/watermark/factory.js +8 -8
- package/dist/extensions/types/basic/events.d.ts +32 -3
- package/dist/extensions/types/basic/events.js +2 -1
- package/dist/extensions/types/basic/mount.d.ts +5 -2
- package/dist/extensions/types/basic/mount.js +0 -2
- package/dist/extensions/types/basic/transient-visuals.d.ts +1 -1
- package/dist/extensions/types/context/animation.d.ts +3 -3
- package/dist/extensions/types/context/events.d.ts +2 -1
- package/dist/extensions/types/context/update.d.ts +6 -7
- package/dist/extensions/types/extension.d.ts +3 -0
- package/dist/extensions/types/main.d.ts +1 -0
- package/dist/extensions/types/surface/commands.d.ts +1 -1
- package/dist/extensions/types/surface/main.d.ts +6 -4
- package/dist/extensions/types/wrapper.d.ts +3 -1
- package/dist/extensions/types/wrapper.js +6 -2
- package/dist/extensions/update.js +6 -10
- package/dist/index.d.ts +1 -1
- package/dist/render/mount.js +3 -3
- package/dist/render/rendering/state.js +2 -2
- package/dist/render/svg/factory.js +40 -25
- package/dist/render/svg/helpers.d.ts +8 -4
- package/dist/render/svg/helpers.js +27 -12
- package/dist/render/svg/ids.d.ts +6 -0
- package/dist/render/svg/ids.js +11 -0
- package/dist/render/types.d.ts +4 -3
- package/dist/render/types.js +2 -1
- package/dist/runtime/factory/input.d.ts +3 -1
- package/dist/runtime/factory/input.js +11 -2
- package/dist/runtime/factory/main.js +10 -4
- package/dist/runtime/input/adapter/event.js +2 -2
- package/dist/runtime/input/adapter/pointer.d.ts +2 -2
- package/dist/runtime/input/controller/factory.d.ts +1 -1
- package/dist/runtime/input/controller/factory.js +35 -15
- package/dist/runtime/input/controller/helpers.d.ts +1 -1
- package/dist/runtime/input/controller/interaction.d.ts +3 -0
- package/dist/runtime/input/controller/interaction.js +14 -0
- package/dist/runtime/input/controller/pointer.d.ts +6 -6
- package/dist/runtime/input/controller/pointer.js +53 -27
- package/dist/runtime/input/controller/transient-visuals.d.ts +2 -3
- package/dist/runtime/input/controller/types.d.ts +6 -5
- package/dist/runtime/types/main.d.ts +1 -1
- package/dist/wrapper/factory.js +2 -7
- package/dist/wrapper/types.d.ts +3 -11
- package/package.json +1 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { InteractionControllerOnEventContext } from '../controller/types.js';
|
|
2
2
|
import { InputAdapterInternal } from './types.js';
|
|
3
|
-
export declare function pointerEventHandler(state: InputAdapterInternal, e: PointerEvent):
|
|
3
|
+
export declare function pointerEventHandler(state: InputAdapterInternal, e: PointerEvent): InteractionControllerOnEventContext;
|
|
4
4
|
/** Release capture for the currently tracked pointer and clear tracking state. */
|
|
5
5
|
export declare function releaseCapture(state: InputAdapterInternal): void;
|
|
6
6
|
export declare function adapterOnPointerDown(state: InputAdapterInternal, e: PointerEvent): void;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { InteractionController, InteractionControllerInitOptions } from './types.js';
|
|
1
|
+
import type { InteractionController, InteractionControllerInitOptions } from './types.js';
|
|
2
2
|
export declare function createInteractionController(options: InteractionControllerInitOptions): InteractionController;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { determineRuntimeInteractionAction } from './interaction.js';
|
|
2
2
|
import { transmitTransientInput } from './transient-visuals.js';
|
|
3
3
|
function createInteractionControllerInternal(options) {
|
|
4
4
|
return {
|
|
@@ -9,24 +9,44 @@ export function createInteractionController(options) {
|
|
|
9
9
|
const internalState = createInteractionControllerInternal(options);
|
|
10
10
|
return {
|
|
11
11
|
onEvent(context) {
|
|
12
|
-
internalState
|
|
12
|
+
const action = determineRuntimeInteractionAction(internalState, context);
|
|
13
|
+
const extensionContext = {
|
|
14
|
+
...context,
|
|
15
|
+
runtimeInteractionActionPreview: action
|
|
16
|
+
};
|
|
17
|
+
internalState.surface.onEvent(extensionContext);
|
|
13
18
|
if (context.rawEvent.defaultPrevented) {
|
|
14
19
|
transmitTransientInput(internalState, context);
|
|
15
20
|
return; // The event has been handled by the surface (extensions)
|
|
16
21
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
22
|
+
if (action) {
|
|
23
|
+
switch (action.type) {
|
|
24
|
+
case 'startLiftedDrag':
|
|
25
|
+
internalState.surface.startLiftedDrag(action.source, action.target);
|
|
26
|
+
break;
|
|
27
|
+
case 'startReleaseTargetingDrag':
|
|
28
|
+
internalState.surface.startReleaseTargetingDrag(action.source, action.target);
|
|
29
|
+
break;
|
|
30
|
+
case 'completeCoreDragTo':
|
|
31
|
+
internalState.surface.completeCoreDragTo(action.target);
|
|
32
|
+
break;
|
|
33
|
+
case 'completeExtensionDrag':
|
|
34
|
+
internalState.surface.completeExtensionDrag(action.target);
|
|
35
|
+
break;
|
|
36
|
+
case 'updateDragSessionCurrentTarget':
|
|
37
|
+
internalState.surface.updateDragSessionCurrentTarget(action.target);
|
|
38
|
+
break;
|
|
39
|
+
case 'cancelActiveInteraction':
|
|
40
|
+
internalState.surface.cancelActiveInteraction();
|
|
41
|
+
break;
|
|
42
|
+
case 'cancelInteraction':
|
|
43
|
+
internalState.surface.cancelInteraction();
|
|
44
|
+
break;
|
|
45
|
+
default:
|
|
46
|
+
throw new Error(
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
48
|
+
`Unhandled RuntimeInteractionAction type: ${String(action.type)}`);
|
|
49
|
+
}
|
|
30
50
|
}
|
|
31
51
|
transmitTransientInput(internalState, context);
|
|
32
52
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { Square } from '../../../state/board/types/internal.js';
|
|
2
|
-
import { InteractionStateSnapshot } from '../../../state/interaction/types/main.js';
|
|
2
|
+
import type { InteractionStateSnapshot } from '../../../state/interaction/types/main.js';
|
|
3
3
|
export declare function canMoveTo(snapshot: InteractionStateSnapshot, target: Square): boolean;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { RuntimeInteractionAction } from '../../../extensions/types/basic/events.js';
|
|
2
|
+
import type { InteractionControllerInternal, InteractionControllerOnEventContext } from './types.js';
|
|
3
|
+
export declare function determineRuntimeInteractionAction(state: InteractionControllerInternal, context: InteractionControllerOnEventContext): RuntimeInteractionAction | null;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { determineActionPointerCancel, determineActionPointerDown, determineActionPointerMove, determineActionPointerUp } from './pointer.js';
|
|
2
|
+
export function determineRuntimeInteractionAction(state, context) {
|
|
3
|
+
switch (context.rawEvent.type) {
|
|
4
|
+
case 'pointerdown':
|
|
5
|
+
return determineActionPointerDown(state, context);
|
|
6
|
+
case 'pointermove':
|
|
7
|
+
return determineActionPointerMove(state, context);
|
|
8
|
+
case 'pointerup':
|
|
9
|
+
return determineActionPointerUp(state, context);
|
|
10
|
+
case 'pointercancel':
|
|
11
|
+
return determineActionPointerCancel(state, context);
|
|
12
|
+
}
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { InteractionControllerInternal } from './types.js';
|
|
3
|
-
export declare function
|
|
4
|
-
export declare function
|
|
5
|
-
export declare function
|
|
6
|
-
export declare function
|
|
1
|
+
import type { RuntimeInteractionAction } from '../../../extensions/types/basic/events.js';
|
|
2
|
+
import type { InteractionControllerInternal, InteractionControllerOnEventContext } from './types.js';
|
|
3
|
+
export declare function determineActionPointerDown(state: InteractionControllerInternal, context: InteractionControllerOnEventContext): RuntimeInteractionAction | null;
|
|
4
|
+
export declare function determineActionPointerMove(state: InteractionControllerInternal, context: InteractionControllerOnEventContext): RuntimeInteractionAction | null;
|
|
5
|
+
export declare function determineActionPointerUp(state: InteractionControllerInternal, context: InteractionControllerOnEventContext): RuntimeInteractionAction | null;
|
|
6
|
+
export declare function determineActionPointerCancel(state: InteractionControllerInternal, context: InteractionControllerOnEventContext): RuntimeInteractionAction | null;
|
|
@@ -3,19 +3,19 @@ import { isEmptyPieceCode, isNonEmptyPieceCode } from '../../../state/board/chec
|
|
|
3
3
|
import { fromPieceCode } from '../../../state/board/piece.js';
|
|
4
4
|
import { isDragSessionCoreOwned } from '../../../state/interaction/helpers.js';
|
|
5
5
|
import { canMoveTo } from './helpers.js';
|
|
6
|
-
export function
|
|
7
|
-
assert(context.rawEvent.type === 'pointerdown', '
|
|
6
|
+
export function determineActionPointerDown(state, context) {
|
|
7
|
+
assert(context.rawEvent.type === 'pointerdown', 'determineActionPointerDown should only be called for pointerdown events');
|
|
8
8
|
const rawEvent = context.rawEvent;
|
|
9
9
|
if (rawEvent.button !== 0) {
|
|
10
10
|
// Only handle left-click for now
|
|
11
|
-
return;
|
|
11
|
+
return null;
|
|
12
12
|
}
|
|
13
13
|
const sceneEvent = context.sceneEvent;
|
|
14
14
|
assert(sceneEvent, 'Scene event should be present for pointer events');
|
|
15
15
|
const interaction = state.surface.getInteractionStateSnapshot();
|
|
16
16
|
if (interaction.dragSession) {
|
|
17
17
|
// Ignore pointer down events if there's already an active drag session
|
|
18
|
-
return;
|
|
18
|
+
return null;
|
|
19
19
|
}
|
|
20
20
|
if (sceneEvent.targetSquare !== null) {
|
|
21
21
|
/**
|
|
@@ -28,16 +28,22 @@ export function handlePointerDown(state, context) {
|
|
|
28
28
|
assert(isNonEmptyPieceCode(selectedPieceCode), 'Selected piece code must be non-zero');
|
|
29
29
|
const targetPieceCode = state.surface.getPieceCodeAt(sceneEvent.targetSquare);
|
|
30
30
|
if (isEmptyPieceCode(targetPieceCode)) {
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
return {
|
|
32
|
+
type: 'startReleaseTargetingDrag',
|
|
33
|
+
source: interaction.selected.square,
|
|
34
|
+
target: sceneEvent.targetSquare
|
|
35
|
+
};
|
|
33
36
|
}
|
|
34
37
|
const isLegalMoveTarget = interaction.movability.mode === 1 /* MovabilityModeCode.Free */ ||
|
|
35
38
|
(interaction.movability.mode === 2 /* MovabilityModeCode.Strict */ &&
|
|
36
39
|
interaction.activeDestinations.has(sceneEvent.targetSquare));
|
|
37
40
|
if (fromPieceCode(targetPieceCode).color !== fromPieceCode(selectedPieceCode).color &&
|
|
38
41
|
isLegalMoveTarget) {
|
|
39
|
-
|
|
40
|
-
|
|
42
|
+
return {
|
|
43
|
+
type: 'startReleaseTargetingDrag',
|
|
44
|
+
source: interaction.selected.square,
|
|
45
|
+
target: sceneEvent.targetSquare
|
|
46
|
+
};
|
|
41
47
|
}
|
|
42
48
|
}
|
|
43
49
|
/**
|
|
@@ -46,60 +52,80 @@ export function handlePointerDown(state, context) {
|
|
|
46
52
|
*/
|
|
47
53
|
const pieceCode = state.surface.getPieceCodeAt(sceneEvent.targetSquare);
|
|
48
54
|
if (!isEmptyPieceCode(pieceCode)) {
|
|
49
|
-
|
|
55
|
+
return {
|
|
56
|
+
type: 'startLiftedDrag',
|
|
57
|
+
source: sceneEvent.targetSquare,
|
|
58
|
+
target: sceneEvent.targetSquare
|
|
59
|
+
};
|
|
50
60
|
}
|
|
51
61
|
}
|
|
62
|
+
return null;
|
|
52
63
|
}
|
|
53
|
-
export function
|
|
54
|
-
assert(context.rawEvent.type === 'pointermove', '
|
|
64
|
+
export function determineActionPointerMove(state, context) {
|
|
65
|
+
assert(context.rawEvent.type === 'pointermove', 'determineActionPointerMove should only be called for pointermove events');
|
|
55
66
|
const interaction = state.surface.getInteractionStateSnapshot();
|
|
56
67
|
if (interaction.dragSession) {
|
|
57
|
-
|
|
68
|
+
return {
|
|
69
|
+
type: 'updateDragSessionCurrentTarget',
|
|
70
|
+
target: context.sceneEvent?.targetSquare ?? null
|
|
71
|
+
};
|
|
58
72
|
}
|
|
73
|
+
return null;
|
|
59
74
|
}
|
|
60
|
-
export function
|
|
61
|
-
assert(context.rawEvent.type === 'pointerup', '
|
|
75
|
+
export function determineActionPointerUp(state, context) {
|
|
76
|
+
assert(context.rawEvent.type === 'pointerup', 'determineActionPointerUp should only be called for pointerup events');
|
|
62
77
|
const interaction = state.surface.getInteractionStateSnapshot();
|
|
63
78
|
const dragSession = interaction.dragSession;
|
|
64
79
|
if (!dragSession) {
|
|
65
80
|
// No active drag session, so nothing to do on pointer up
|
|
66
|
-
return;
|
|
81
|
+
return null;
|
|
67
82
|
}
|
|
68
83
|
const sceneEvent = context.sceneEvent;
|
|
69
84
|
assert(sceneEvent, 'Scene event should be present for pointer events');
|
|
70
85
|
if (!isDragSessionCoreOwned(dragSession)) {
|
|
71
86
|
// For extension-owned drag sessions, we simply end the session without attempting to make a move,
|
|
72
87
|
// since the runtime doesn't have enough information about the semantics of the drag session.
|
|
73
|
-
|
|
74
|
-
|
|
88
|
+
return {
|
|
89
|
+
type: 'completeExtensionDrag',
|
|
90
|
+
target: sceneEvent.targetSquare
|
|
91
|
+
};
|
|
75
92
|
}
|
|
76
93
|
// Check if the square is the same as the source square of the drag session.
|
|
77
94
|
// If it is, then we can end the drag session without making a move.
|
|
78
95
|
if (sceneEvent.targetSquare === dragSession.sourceSquare) {
|
|
79
|
-
|
|
80
|
-
|
|
96
|
+
return {
|
|
97
|
+
type: 'cancelActiveInteraction'
|
|
98
|
+
};
|
|
81
99
|
}
|
|
82
100
|
// Check if the target square is a valid destination for the selected piece.
|
|
83
101
|
if (sceneEvent.targetSquare !== null && canMoveTo(interaction, sceneEvent.targetSquare)) {
|
|
84
|
-
|
|
85
|
-
|
|
102
|
+
return {
|
|
103
|
+
type: 'completeCoreDragTo',
|
|
104
|
+
target: sceneEvent.targetSquare
|
|
105
|
+
};
|
|
86
106
|
}
|
|
87
107
|
// Invalid target: piece returns to source for lifted drag (selection preserved),
|
|
88
108
|
// or selection is cleared for release targeting.
|
|
89
109
|
if (dragSession.type === 'lifted-piece-drag') {
|
|
90
|
-
|
|
110
|
+
return {
|
|
111
|
+
type: 'cancelActiveInteraction'
|
|
112
|
+
};
|
|
91
113
|
}
|
|
92
114
|
else {
|
|
93
|
-
|
|
115
|
+
return {
|
|
116
|
+
type: 'cancelInteraction'
|
|
117
|
+
};
|
|
94
118
|
}
|
|
95
119
|
}
|
|
96
|
-
export function
|
|
97
|
-
assert(context.rawEvent.type === 'pointercancel', '
|
|
120
|
+
export function determineActionPointerCancel(state, context) {
|
|
121
|
+
assert(context.rawEvent.type === 'pointercancel', 'determineActionPointerCancel should only be called for pointercancel events');
|
|
98
122
|
const interaction = state.surface.getInteractionStateSnapshot();
|
|
99
123
|
if (!interaction.dragSession) {
|
|
100
124
|
// No active drag session, so nothing to do on pointer cancel
|
|
101
|
-
return;
|
|
125
|
+
return null;
|
|
102
126
|
}
|
|
103
127
|
// Cancel the active interaction on pointer cancel
|
|
104
|
-
|
|
128
|
+
return {
|
|
129
|
+
type: 'cancelActiveInteraction'
|
|
130
|
+
};
|
|
105
131
|
}
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export declare function transmitTransientInput(state: InteractionControllerInternal, context: ExtensionOnEventContext): void;
|
|
1
|
+
import type { InteractionControllerInternal, InteractionControllerOnEventContext } from './types.js';
|
|
2
|
+
export declare function transmitTransientInput(state: InteractionControllerInternal, context: InteractionControllerOnEventContext): void;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { TransientInput } from '../../../extensions/types/basic/transient-visuals.js';
|
|
2
|
-
import { ExtensionOnEventContext } from '../../../extensions/types/context/events.js';
|
|
3
|
-
import { PieceCode, Square } from '../../../state/board/types/internal.js';
|
|
4
|
-
import { InteractionStateSnapshot } from '../../../state/interaction/types/main.js';
|
|
1
|
+
import type { TransientInput } from '../../../extensions/types/basic/transient-visuals.js';
|
|
2
|
+
import type { ExtensionOnEventContext } from '../../../extensions/types/context/events.js';
|
|
3
|
+
import type { PieceCode, Square } from '../../../state/board/types/internal.js';
|
|
4
|
+
import type { InteractionStateSnapshot } from '../../../state/interaction/types/main.js';
|
|
5
5
|
export interface RuntimeInteractionSurface {
|
|
6
6
|
getInteractionStateSnapshot(): InteractionStateSnapshot;
|
|
7
7
|
getPieceCodeAt(square: Square): PieceCode;
|
|
@@ -21,6 +21,7 @@ export interface InteractionControllerInternal {
|
|
|
21
21
|
export interface InteractionControllerInitOptions {
|
|
22
22
|
surface: RuntimeInteractionSurface;
|
|
23
23
|
}
|
|
24
|
+
export type InteractionControllerOnEventContext = Omit<ExtensionOnEventContext, 'runtimeInteractionActionPreview'>;
|
|
24
25
|
export interface InteractionController {
|
|
25
|
-
onEvent(context:
|
|
26
|
+
onEvent(context: InteractionControllerOnEventContext): void;
|
|
26
27
|
}
|
|
@@ -14,7 +14,7 @@ export interface RuntimeInternal extends RuntimeMutationPipelineContext {
|
|
|
14
14
|
}
|
|
15
15
|
export type GetInternalState = () => RuntimeInternal;
|
|
16
16
|
export interface RuntimeInitOptions {
|
|
17
|
-
|
|
17
|
+
element: HTMLElement;
|
|
18
18
|
state?: RuntimeStateInitOptions;
|
|
19
19
|
extensions?: readonly AnyExtensionDefinition[];
|
|
20
20
|
}
|
package/dist/wrapper/factory.js
CHANGED
|
@@ -19,18 +19,13 @@ export function createBoard(options) {
|
|
|
19
19
|
// assume it's already a definition
|
|
20
20
|
return ext;
|
|
21
21
|
});
|
|
22
|
-
const doc = 'document' in options && options.document ? options.document : options.element.ownerDocument;
|
|
23
22
|
const runtime = createRuntime({
|
|
24
|
-
|
|
23
|
+
element: options.element,
|
|
25
24
|
state: options.state,
|
|
26
25
|
extensions
|
|
27
26
|
});
|
|
28
|
-
|
|
29
|
-
runtime.mount(options.element);
|
|
30
|
-
}
|
|
27
|
+
runtime.mount(options.element);
|
|
31
28
|
return {
|
|
32
|
-
mount: runtime.mount,
|
|
33
|
-
unmount: runtime.unmount,
|
|
34
29
|
destroy: runtime.destroy,
|
|
35
30
|
setPosition: runtime.setPosition,
|
|
36
31
|
setPiecePosition: runtime.setPiecePosition,
|
package/dist/wrapper/types.d.ts
CHANGED
|
@@ -43,23 +43,15 @@ export type ChessboardExtensionsPublicMap<TExtensions extends readonly Chessboar
|
|
|
43
43
|
/**
|
|
44
44
|
* Public createBoard options
|
|
45
45
|
*/
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
readonly element?: never;
|
|
49
|
-
}
|
|
50
|
-
interface ChessboardInitOptionsElement {
|
|
51
|
-
readonly element: HTMLElement;
|
|
52
|
-
readonly document?: never;
|
|
53
|
-
}
|
|
54
|
-
type ChessboardInitTarget = ChessboardInitOptionsDocument | ChessboardInitOptionsElement;
|
|
55
|
-
export type ChessboardInitOptions<TExtensions extends readonly ChessboardExtensionInput[] = DefaultBuiltinChessboardExtensions> = ChessboardInitTarget & {
|
|
46
|
+
export type ChessboardInitOptions<TExtensions extends readonly ChessboardExtensionInput[] = DefaultBuiltinChessboardExtensions> = {
|
|
47
|
+
element: HTMLElement;
|
|
56
48
|
readonly state?: RuntimeStateInitOptions;
|
|
57
49
|
readonly extensions?: TExtensions;
|
|
58
50
|
};
|
|
59
51
|
/**
|
|
60
52
|
* Public board interface returned by createBoard(...)
|
|
61
53
|
*/
|
|
62
|
-
export type ChessboardRuntimeSurface = Pick<Runtime, '
|
|
54
|
+
export type ChessboardRuntimeSurface = Pick<Runtime, 'destroy' | 'move' | 'setPosition' | 'setPiecePosition' | 'setTurn' | 'setOrientation' | 'setMovability' | 'select' | 'getSnapshot'>;
|
|
63
55
|
export interface Chessboard<TExtensions extends readonly ChessboardExtensionInput[] = DefaultBuiltinChessboardExtensions> extends ChessboardRuntimeSurface {
|
|
64
56
|
readonly extensions: ChessboardExtensionsPublicMap<TExtensions>;
|
|
65
57
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mirasen/chessboard",
|
|
3
3
|
"description": "Framework-agnostic TypeScript chessboard platform with real chess interaction built in.",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.2.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Mirasen",
|
|
@@ -54,7 +54,6 @@
|
|
|
54
54
|
"scripts": {
|
|
55
55
|
"build": "rimraf ./dist && tsc --project tsconfig.json && npm run prepack",
|
|
56
56
|
"build:release": "rimraf ./dist && tsc --project tsconfig-release.json && npm run prepack",
|
|
57
|
-
"prepare": "bash ./scripts/npm-link.sh",
|
|
58
57
|
"prepack": "publint",
|
|
59
58
|
"format": "prettier --write .",
|
|
60
59
|
"lint": "prettier --check . && eslint .",
|
|
@@ -92,7 +91,6 @@
|
|
|
92
91
|
"publint": "^0.3.11",
|
|
93
92
|
"rimraf": "^6.0.1",
|
|
94
93
|
"serve": "^14.2.6",
|
|
95
|
-
"tsc-alias": "^1.8.15",
|
|
96
94
|
"typescript": "^5.8.2",
|
|
97
95
|
"typescript-eslint": "^8.57.0",
|
|
98
96
|
"vitest": "^4.0.18"
|