@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,5 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
export declare function mapBoardPointToSquare(x: number, y: number, geometry: RenderGeometry): Square | null;
|
|
5
|
-
export declare function clampBoardPoint(point: ScenePoint, geometry: RenderGeometry): ScenePoint;
|
|
1
|
+
import { ScenePointerEvent } from '../../../extensions/types/basic/events.js';
|
|
2
|
+
import { InputAdapterInternal } from './types.js';
|
|
3
|
+
export declare function makeScenePointerEvent(state: InputAdapterInternal, e: PointerEvent): ScenePointerEvent;
|
|
@@ -1,12 +1,67 @@
|
|
|
1
|
-
export function
|
|
1
|
+
export function makeScenePointerEvent(state, e) {
|
|
2
|
+
const containerRect = state.container.getBoundingClientRect();
|
|
3
|
+
const sceneRect = makeSceneRectFromDOMRect(containerRect);
|
|
4
|
+
const point = toScenePoint(e, containerRect);
|
|
5
|
+
const clampedPoint = clampToSceneRect(point, sceneRect);
|
|
6
|
+
let clampedToBoardPoint = null;
|
|
7
|
+
let targetSquare = null;
|
|
8
|
+
const geometry = state.getRenderGeometry();
|
|
9
|
+
if (geometry) {
|
|
10
|
+
const sceneBoardRect = geometry.boardRect;
|
|
11
|
+
clampedToBoardPoint = clampToSceneRect(point, sceneBoardRect);
|
|
12
|
+
targetSquare = mapScenePointToSquare(point, geometry);
|
|
13
|
+
}
|
|
14
|
+
return {
|
|
15
|
+
// DOM part
|
|
16
|
+
type: e.type,
|
|
17
|
+
// scene part
|
|
18
|
+
point,
|
|
19
|
+
clampedPoint,
|
|
20
|
+
boardClampedPoint: clampedToBoardPoint,
|
|
21
|
+
// board part
|
|
22
|
+
targetSquare
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function toScenePoint(e, inRect) {
|
|
26
|
+
return {
|
|
27
|
+
x: e.clientX - inRect.x,
|
|
28
|
+
y: e.clientY - inRect.y
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function makeSceneRectFromDOMRect(domRect) {
|
|
32
|
+
return {
|
|
33
|
+
x: 0,
|
|
34
|
+
y: 0,
|
|
35
|
+
width: domRect.width,
|
|
36
|
+
height: domRect.height
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function clampToSceneRect(point, boundRect) {
|
|
40
|
+
// X cannot go below boundRect.x, cannot go above boundRect.x + boundRect.width
|
|
41
|
+
// Y cannot go below boundRect.y, cannot go above boundRect.y + boundRect.height
|
|
42
|
+
return {
|
|
43
|
+
x: Math.max(boundRect.x, Math.min(point.x, boundRect.x + boundRect.width)),
|
|
44
|
+
y: Math.max(boundRect.y, Math.min(point.y, boundRect.y + boundRect.height))
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function mapScenePointToSquare(point, geometry) {
|
|
48
|
+
const { x, y } = point;
|
|
2
49
|
if (!Number.isFinite(x) || !Number.isFinite(y))
|
|
3
50
|
return null;
|
|
4
|
-
const
|
|
5
|
-
|
|
51
|
+
const orientation = geometry.orientation;
|
|
52
|
+
const boardRect = geometry.boardRect;
|
|
53
|
+
const boardSize = boardRect.width;
|
|
54
|
+
const squareSize = geometry.squareSize;
|
|
55
|
+
if (x < boardRect.x ||
|
|
56
|
+
x >= boardRect.x + boardSize ||
|
|
57
|
+
y < boardRect.y ||
|
|
58
|
+
y >= boardRect.y + boardSize)
|
|
6
59
|
return null;
|
|
7
60
|
// Grid cell indices, each in [0, 7].
|
|
8
|
-
const xIndex = Math.floor(x / squareSize);
|
|
9
|
-
const yIndex = Math.floor(y / squareSize);
|
|
61
|
+
const xIndex = Math.floor((x - boardRect.x) / squareSize);
|
|
62
|
+
const yIndex = Math.floor((y - boardRect.y) / squareSize);
|
|
63
|
+
if (xIndex < 0 || xIndex > 7 || yIndex < 0 || yIndex > 7)
|
|
64
|
+
return null;
|
|
10
65
|
// Invert the orientation mapping used by geometry.squareRect:
|
|
11
66
|
// white: xIndex = file, yIndex = 7 - rank → file = xIndex, rank = 7 - yIndex
|
|
12
67
|
// black: xIndex = 7 - file, yIndex = rank → file = 7 - xIndex, rank = yIndex
|
|
@@ -14,10 +69,3 @@ export function mapBoardPointToSquare(x, y, geometry) {
|
|
|
14
69
|
const rank = orientation === 0 /* ColorCode.White */ ? 7 - yIndex : yIndex;
|
|
15
70
|
return (rank * 8 + file);
|
|
16
71
|
}
|
|
17
|
-
export function clampBoardPoint(point, geometry) {
|
|
18
|
-
const { boardSize } = geometry;
|
|
19
|
-
return {
|
|
20
|
-
x: Math.min(Math.max(point.x, 0), boardSize),
|
|
21
|
-
y: Math.min(Math.max(point.y, 0), boardSize)
|
|
22
|
-
};
|
|
23
|
-
}
|
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { InputAdapterInternal } from './types';
|
|
3
|
-
export
|
|
4
|
-
type: ScenePointerEventType;
|
|
5
|
-
};
|
|
6
|
-
export declare function isPointerRelevantEvent(e: PointerEvent): e is PointerRelevantEvent;
|
|
1
|
+
import { ExtensionOnEventContext } from '../../../extensions/types/context/events.js';
|
|
2
|
+
import { InputAdapterInternal } from './types.js';
|
|
3
|
+
export declare function pointerEventHandler(state: InputAdapterInternal, e: PointerEvent): ExtensionOnEventContext;
|
|
7
4
|
/** Release capture for the currently tracked pointer and clear tracking state. */
|
|
8
5
|
export declare function releaseCapture(state: InputAdapterInternal): void;
|
|
9
|
-
export declare function
|
|
10
|
-
export declare function
|
|
11
|
-
export declare function
|
|
12
|
-
export declare function
|
|
13
|
-
export declare function onPointerLeave(state: InputAdapterInternal, e: PointerRelevantEvent): void;
|
|
6
|
+
export declare function adapterOnPointerDown(state: InputAdapterInternal, e: PointerEvent): void;
|
|
7
|
+
export declare function adapterOnPointerUp(state: InputAdapterInternal, e: PointerEvent): void;
|
|
8
|
+
export declare function adapterOnPointerCancel(state: InputAdapterInternal, e: PointerEvent): void;
|
|
9
|
+
export declare function pointerEventDestroy(state: InputAdapterInternal): void;
|
|
@@ -1,9 +1,30 @@
|
|
|
1
1
|
import assert from '@ktarmyshov/assert';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
import { ALL_SCENE_POINTER_EVENT_TYPES } from '../../../extensions/types/basic/events.js';
|
|
3
|
+
import { makeScenePointerEvent } from './helpers.js';
|
|
4
|
+
export function pointerEventHandler(state, e) {
|
|
5
|
+
assert(ALL_SCENE_POINTER_EVENT_TYPES.has(e.type), `Unexpected pointer event type: ${e.type}`);
|
|
6
|
+
// First convert to scene event for controller
|
|
7
|
+
const sceneEvent = makeScenePointerEvent(state, e);
|
|
8
|
+
// Then handle pointer event within the adapter logic (e.g. tracking active pointer, capturing, etc.)
|
|
9
|
+
pointerEventAdapterHandler(state, e);
|
|
10
|
+
// Then create context and pass to controller for extension handling
|
|
11
|
+
return {
|
|
12
|
+
rawEvent: e,
|
|
13
|
+
sceneEvent
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function pointerEventAdapterHandler(state, e) {
|
|
17
|
+
switch (e.type) {
|
|
18
|
+
case 'pointerdown':
|
|
19
|
+
adapterOnPointerDown(state, e);
|
|
20
|
+
break;
|
|
21
|
+
case 'pointerup':
|
|
22
|
+
adapterOnPointerUp(state, e);
|
|
23
|
+
break;
|
|
24
|
+
case 'pointercancel':
|
|
25
|
+
adapterOnPointerCancel(state, e);
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
7
28
|
}
|
|
8
29
|
/** Release capture for the currently tracked pointer and clear tracking state. */
|
|
9
30
|
export function releaseCapture(state) {
|
|
@@ -14,84 +35,30 @@ export function releaseCapture(state) {
|
|
|
14
35
|
}
|
|
15
36
|
state.activePointerId = null;
|
|
16
37
|
}
|
|
17
|
-
function
|
|
18
|
-
|
|
19
|
-
if (!geometry)
|
|
20
|
-
return { target: null, rawPoint: null, clampedPoint: null };
|
|
21
|
-
const rect = state.container.getBoundingClientRect();
|
|
22
|
-
const x = e.clientX - rect.left;
|
|
23
|
-
const y = e.clientY - rect.top;
|
|
24
|
-
const target = mapBoardPointToSquare(x, y, geometry);
|
|
25
|
-
const point = { x, y };
|
|
26
|
-
return { target, rawPoint: point, clampedPoint: clampBoardPoint(point, geometry) };
|
|
27
|
-
}
|
|
28
|
-
function makeBoardPointerEvent(e, pointerTarget) {
|
|
29
|
-
assert(e.defaultPrevented === false, 'Expected event to be unhandled before making BoardPointerEvent');
|
|
30
|
-
let defaultPrevented = false;
|
|
31
|
-
return {
|
|
32
|
-
type: e.type,
|
|
33
|
-
// DOM part
|
|
34
|
-
pointerId: e.pointerId,
|
|
35
|
-
isPrimary: e.isPrimary,
|
|
36
|
-
button: e.button,
|
|
37
|
-
buttons: e.buttons,
|
|
38
|
-
ctrlKey: e.ctrlKey,
|
|
39
|
-
altKey: e.altKey,
|
|
40
|
-
shiftKey: e.shiftKey,
|
|
41
|
-
metaKey: e.metaKey,
|
|
42
|
-
// Board part
|
|
43
|
-
rawPoint: pointerTarget.rawPoint,
|
|
44
|
-
clampedPoint: pointerTarget.clampedPoint,
|
|
45
|
-
target: pointerTarget.target,
|
|
46
|
-
// Mechanics
|
|
47
|
-
get defaultPrevented() {
|
|
48
|
-
return defaultPrevented;
|
|
49
|
-
},
|
|
50
|
-
preventDefault() {
|
|
51
|
-
defaultPrevented = true;
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
export function onPointerDown(state, e) {
|
|
38
|
+
export function adapterOnPointerDown(state, e) {
|
|
39
|
+
assert(e.type === 'pointerdown', `Expected pointerdown event, got ${e.type}`);
|
|
56
40
|
if (!e.isPrimary)
|
|
57
41
|
return; // ignore non-primary pointers
|
|
58
42
|
if (state.activePointerId !== null)
|
|
59
43
|
return; // already tracking
|
|
60
44
|
state.activePointerId = e.pointerId;
|
|
61
45
|
state.container.setPointerCapture(e.pointerId);
|
|
62
|
-
const pointerTarget = resolvePointerTarget(state, e);
|
|
63
|
-
const boardEvent = makeBoardPointerEvent(e, pointerTarget);
|
|
64
|
-
e.preventDefault(); // prevent native text selection during drag
|
|
65
|
-
state.controller.onEvent(boardEvent);
|
|
66
46
|
}
|
|
67
|
-
export function
|
|
47
|
+
export function adapterOnPointerUp(state, e) {
|
|
48
|
+
assert(e.type === 'pointerup', `Expected pointerup event, got ${e.type}`);
|
|
68
49
|
if (e.pointerId !== state.activePointerId)
|
|
69
50
|
return;
|
|
70
|
-
const pointerTarget = resolvePointerTarget(state, e);
|
|
71
|
-
const boardEvent = makeBoardPointerEvent(e, pointerTarget);
|
|
72
|
-
e.preventDefault(); // prevent native text selection during drag
|
|
73
|
-
state.controller.onEvent(boardEvent);
|
|
74
|
-
}
|
|
75
|
-
export function onPointerUp(state, e) {
|
|
76
|
-
if (e.pointerId !== state.activePointerId)
|
|
77
|
-
return;
|
|
78
|
-
const pointerTarget = resolvePointerTarget(state, e); // resolve before releasing capture
|
|
79
51
|
releaseCapture(state);
|
|
80
|
-
const boardEvent = makeBoardPointerEvent(e, pointerTarget);
|
|
81
|
-
state.controller.onEvent(boardEvent);
|
|
82
52
|
}
|
|
83
|
-
export function
|
|
53
|
+
export function adapterOnPointerCancel(state, e) {
|
|
54
|
+
assert(e.type === 'pointercancel', `Expected pointercancel event, got ${e.type}`);
|
|
84
55
|
if (e.pointerId !== state.activePointerId)
|
|
85
56
|
return;
|
|
86
|
-
const pointerTarget = resolvePointerTarget(state, e); // resolve before releasing capture
|
|
87
57
|
releaseCapture(state);
|
|
88
|
-
const boardEvent = makeBoardPointerEvent(e, pointerTarget);
|
|
89
|
-
state.controller.onEvent(boardEvent);
|
|
90
58
|
}
|
|
91
|
-
export function
|
|
92
|
-
if (
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
state.controller.onEvent(boardEvent);
|
|
59
|
+
export function pointerEventDestroy(state) {
|
|
60
|
+
if (state.activePointerId !== null) {
|
|
61
|
+
releaseCapture(state);
|
|
62
|
+
}
|
|
63
|
+
state.activePointerId = null;
|
|
97
64
|
}
|
|
@@ -1,16 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { InteractionController } from '../controller/types';
|
|
1
|
+
import { SceneRenderGeometry } from '../../../layout/geometry/types.js';
|
|
2
|
+
import { InteractionController } from '../controller/types.js';
|
|
3
3
|
export interface InputAdapterInitOptions {
|
|
4
4
|
container: HTMLElement;
|
|
5
|
-
|
|
5
|
+
getRenderGeometry: () => SceneRenderGeometry | null;
|
|
6
6
|
controller: InteractionController;
|
|
7
7
|
}
|
|
8
8
|
export interface InputAdapterInternal {
|
|
9
9
|
readonly container: HTMLElement;
|
|
10
|
-
readonly
|
|
10
|
+
readonly getRenderGeometry: () => SceneRenderGeometry | null;
|
|
11
11
|
readonly controller: InteractionController;
|
|
12
12
|
activePointerId: number | null;
|
|
13
13
|
}
|
|
14
14
|
export interface InputAdapter {
|
|
15
|
+
subscribeEvent<K extends keyof HTMLElementEventMap>(type: K): void;
|
|
16
|
+
unsubscribeEvent<K extends keyof HTMLElementEventMap>(type: K): void;
|
|
15
17
|
destroy(): void;
|
|
16
18
|
}
|
|
19
|
+
export declare const NEED_EVENT_TYPES: Set<string>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { InteractionController, InteractionControllerInitOptions } from './types';
|
|
1
|
+
import { InteractionController, InteractionControllerInitOptions } from './types.js';
|
|
2
2
|
export declare function createInteractionController(options: InteractionControllerInitOptions): InteractionController;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { handlePointerCancel, handlePointerDown,
|
|
2
|
-
import { transmitTransientInput } from './transient-visuals';
|
|
1
|
+
import { handlePointerCancel, handlePointerDown, handlePointerMove, handlePointerUp } from './pointer.js';
|
|
2
|
+
import { transmitTransientInput } from './transient-visuals.js';
|
|
3
3
|
function createInteractionControllerInternal(options) {
|
|
4
4
|
return {
|
|
5
5
|
surface: options.surface
|
|
@@ -8,25 +8,26 @@ function createInteractionControllerInternal(options) {
|
|
|
8
8
|
export function createInteractionController(options) {
|
|
9
9
|
const internalState = createInteractionControllerInternal(options);
|
|
10
10
|
return {
|
|
11
|
-
onEvent(
|
|
12
|
-
|
|
11
|
+
onEvent(context) {
|
|
12
|
+
internalState.surface.onEvent(context);
|
|
13
|
+
if (context.rawEvent.defaultPrevented) {
|
|
14
|
+
return; // The event has been handled by the surface (extensions)
|
|
15
|
+
}
|
|
16
|
+
switch (context.rawEvent.type) {
|
|
13
17
|
case 'pointerdown':
|
|
14
|
-
handlePointerDown(internalState,
|
|
18
|
+
handlePointerDown(internalState, context);
|
|
15
19
|
break;
|
|
16
20
|
case 'pointermove':
|
|
17
|
-
handlePointerMove(internalState,
|
|
21
|
+
handlePointerMove(internalState, context);
|
|
18
22
|
break;
|
|
19
23
|
case 'pointerup':
|
|
20
|
-
handlePointerUp(internalState,
|
|
24
|
+
handlePointerUp(internalState, context);
|
|
21
25
|
break;
|
|
22
26
|
case 'pointercancel':
|
|
23
|
-
handlePointerCancel(internalState,
|
|
24
|
-
break;
|
|
25
|
-
case 'pointerleave':
|
|
26
|
-
handlePointerLeave(internalState, event);
|
|
27
|
+
handlePointerCancel(internalState, context);
|
|
27
28
|
break;
|
|
28
29
|
}
|
|
29
|
-
transmitTransientInput(internalState,
|
|
30
|
+
transmitTransientInput(internalState, context);
|
|
30
31
|
}
|
|
31
32
|
};
|
|
32
33
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { Square } from '../../../state/board/types/internal';
|
|
2
|
-
import { InteractionStateSnapshot } from '../../../state/interaction/types/main';
|
|
1
|
+
import type { Square } from '../../../state/board/types/internal.js';
|
|
2
|
+
import { InteractionStateSnapshot } from '../../../state/interaction/types/main.js';
|
|
3
3
|
export declare function canMoveTo(snapshot: InteractionStateSnapshot, target: Square): boolean;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { InteractionControllerInternal } from './types';
|
|
3
|
-
export declare function handlePointerDown(state: InteractionControllerInternal,
|
|
4
|
-
export declare function handlePointerMove(state: InteractionControllerInternal,
|
|
5
|
-
export declare function handlePointerUp(state: InteractionControllerInternal,
|
|
6
|
-
export declare function handlePointerCancel(state: InteractionControllerInternal,
|
|
7
|
-
export declare function handlePointerLeave(state: InteractionControllerInternal, event: ScenePointerEvent): void;
|
|
1
|
+
import { ExtensionOnEventContext } from '../../../extensions/types/context/events.js';
|
|
2
|
+
import { InteractionControllerInternal } from './types.js';
|
|
3
|
+
export declare function handlePointerDown(state: InteractionControllerInternal, context: ExtensionOnEventContext): void;
|
|
4
|
+
export declare function handlePointerMove(state: InteractionControllerInternal, context: ExtensionOnEventContext): void;
|
|
5
|
+
export declare function handlePointerUp(state: InteractionControllerInternal, context: ExtensionOnEventContext): void;
|
|
6
|
+
export declare function handlePointerCancel(state: InteractionControllerInternal, context: ExtensionOnEventContext): void;
|
|
@@ -1,38 +1,42 @@
|
|
|
1
1
|
import assert from '@ktarmyshov/assert';
|
|
2
|
-
import { isEmptyPieceCode, isNonEmptyPieceCode } from '../../../state/board/check';
|
|
3
|
-
import { fromPieceCode } from '../../../state/board/piece';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
import { isEmptyPieceCode, isNonEmptyPieceCode } from '../../../state/board/check.js';
|
|
3
|
+
import { fromPieceCode } from '../../../state/board/piece.js';
|
|
4
|
+
import { isDragSessionCoreOwned } from '../../../state/interaction/helpers.js';
|
|
5
|
+
import { canMoveTo } from './helpers.js';
|
|
6
|
+
export function handlePointerDown(state, context) {
|
|
7
|
+
assert(context.rawEvent.type === 'pointerdown', 'handlePointerDown should only be called for pointerdown events');
|
|
8
|
+
const rawEvent = context.rawEvent;
|
|
9
|
+
if (rawEvent.button !== 0) {
|
|
8
10
|
// Only handle left-click for now
|
|
9
11
|
return;
|
|
10
12
|
}
|
|
13
|
+
const sceneEvent = context.sceneEvent;
|
|
14
|
+
assert(sceneEvent, 'Scene event should be present for pointer events');
|
|
11
15
|
const interaction = state.surface.getInteractionStateSnapshot();
|
|
12
16
|
if (interaction.dragSession) {
|
|
13
17
|
// Ignore pointer down events if there's already an active drag session
|
|
14
18
|
return;
|
|
15
19
|
}
|
|
16
|
-
if (
|
|
20
|
+
if (sceneEvent.targetSquare !== null) {
|
|
17
21
|
/**
|
|
18
22
|
* If piece is already selected, and we have a valid target square event.target
|
|
19
23
|
* AND it's a different square AND (it's empty OR (has an opponent piece AND is a legal move target))
|
|
20
24
|
* THEN start a release-targeting drag session
|
|
21
25
|
*/
|
|
22
|
-
if (interaction.selected &&
|
|
26
|
+
if (interaction.selected && sceneEvent.targetSquare !== interaction.selected.square) {
|
|
23
27
|
const selectedPieceCode = interaction.selected.pieceCode;
|
|
24
28
|
assert(isNonEmptyPieceCode(selectedPieceCode), 'Selected piece code must be non-zero');
|
|
25
|
-
const targetPieceCode = state.surface.getPieceCodeAt(
|
|
29
|
+
const targetPieceCode = state.surface.getPieceCodeAt(sceneEvent.targetSquare);
|
|
26
30
|
if (isEmptyPieceCode(targetPieceCode)) {
|
|
27
|
-
state.surface.startReleaseTargetingDrag(interaction.selected.square,
|
|
31
|
+
state.surface.startReleaseTargetingDrag(interaction.selected.square, sceneEvent.targetSquare);
|
|
28
32
|
return;
|
|
29
33
|
}
|
|
30
34
|
const isLegalMoveTarget = interaction.movability.mode === 1 /* MovabilityModeCode.Free */ ||
|
|
31
35
|
(interaction.movability.mode === 2 /* MovabilityModeCode.Strict */ &&
|
|
32
|
-
interaction.activeDestinations.has(
|
|
36
|
+
interaction.activeDestinations.has(sceneEvent.targetSquare));
|
|
33
37
|
if (fromPieceCode(targetPieceCode).color !== fromPieceCode(selectedPieceCode).color &&
|
|
34
38
|
isLegalMoveTarget) {
|
|
35
|
-
state.surface.startReleaseTargetingDrag(interaction.selected.square,
|
|
39
|
+
state.surface.startReleaseTargetingDrag(interaction.selected.square, sceneEvent.targetSquare);
|
|
36
40
|
return;
|
|
37
41
|
}
|
|
38
42
|
}
|
|
@@ -40,53 +44,57 @@ export function handlePointerDown(state, event) {
|
|
|
40
44
|
* If we are here, then it's not release-targeting.
|
|
41
45
|
* So it's either a new lift or re-lift of the same piece. In either case, we can just start a lifted drag session if the target is valid.
|
|
42
46
|
*/
|
|
43
|
-
const pieceCode = state.surface.getPieceCodeAt(
|
|
47
|
+
const pieceCode = state.surface.getPieceCodeAt(sceneEvent.targetSquare);
|
|
44
48
|
if (!isEmptyPieceCode(pieceCode)) {
|
|
45
|
-
state.surface.startLiftedDrag(
|
|
49
|
+
state.surface.startLiftedDrag(sceneEvent.targetSquare, sceneEvent.targetSquare);
|
|
46
50
|
}
|
|
47
51
|
}
|
|
48
52
|
}
|
|
49
|
-
export function handlePointerMove(state,
|
|
50
|
-
assert(
|
|
53
|
+
export function handlePointerMove(state, context) {
|
|
54
|
+
assert(context.rawEvent.type === 'pointermove', 'handlePointerMove should only be called for pointermove events');
|
|
51
55
|
const interaction = state.surface.getInteractionStateSnapshot();
|
|
52
56
|
if (interaction.dragSession) {
|
|
53
|
-
state.surface.updateDragSessionCurrentTarget(
|
|
57
|
+
state.surface.updateDragSessionCurrentTarget(context.sceneEvent?.targetSquare ?? null);
|
|
54
58
|
}
|
|
55
59
|
}
|
|
56
|
-
export function handlePointerUp(state,
|
|
57
|
-
assert(
|
|
60
|
+
export function handlePointerUp(state, context) {
|
|
61
|
+
assert(context.rawEvent.type === 'pointerup', 'handlePointerUp should only be called for pointerup events');
|
|
58
62
|
const interaction = state.surface.getInteractionStateSnapshot();
|
|
59
|
-
|
|
63
|
+
const dragSession = interaction.dragSession;
|
|
64
|
+
if (!dragSession) {
|
|
60
65
|
// No active drag session, so nothing to do on pointer up
|
|
61
66
|
return;
|
|
62
67
|
}
|
|
68
|
+
const sceneEvent = context.sceneEvent;
|
|
69
|
+
assert(sceneEvent, 'Scene event should be present for pointer events');
|
|
70
|
+
if (!isDragSessionCoreOwned(dragSession)) {
|
|
71
|
+
// For extension-owned drag sessions, we simply end the session without attempting to make a move,
|
|
72
|
+
// since the runtime doesn't have enough information about the semantics of the drag session.
|
|
73
|
+
state.surface.completeExtensionDrag(sceneEvent.targetSquare);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
63
76
|
// Check if the square is the same as the source square of the drag session.
|
|
64
77
|
// If it is, then we can end the drag session without making a move.
|
|
65
|
-
if (
|
|
78
|
+
if (sceneEvent.targetSquare === dragSession.sourceSquare) {
|
|
66
79
|
state.surface.cancelActiveInteraction();
|
|
67
80
|
return;
|
|
68
81
|
}
|
|
69
82
|
// Check if the target square is a valid destination for the selected piece.
|
|
70
|
-
if (
|
|
71
|
-
|
|
72
|
-
state.surface.dropTo(event.target);
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
state.surface.releaseTo(event.target);
|
|
76
|
-
}
|
|
83
|
+
if (sceneEvent.targetSquare !== null && canMoveTo(interaction, sceneEvent.targetSquare)) {
|
|
84
|
+
state.surface.completeCoreDragTo(sceneEvent.targetSquare);
|
|
77
85
|
return;
|
|
78
86
|
}
|
|
79
87
|
// Invalid target: piece returns to source for lifted drag (selection preserved),
|
|
80
88
|
// or selection is cleared for release targeting.
|
|
81
|
-
if (
|
|
89
|
+
if (dragSession.type === 'lifted-piece-drag') {
|
|
82
90
|
state.surface.cancelActiveInteraction();
|
|
83
91
|
}
|
|
84
92
|
else {
|
|
85
93
|
state.surface.cancelInteraction();
|
|
86
94
|
}
|
|
87
95
|
}
|
|
88
|
-
export function handlePointerCancel(state,
|
|
89
|
-
assert(
|
|
96
|
+
export function handlePointerCancel(state, context) {
|
|
97
|
+
assert(context.rawEvent.type === 'pointercancel', 'handlePointerCancel should only be called for pointercancel events');
|
|
90
98
|
const interaction = state.surface.getInteractionStateSnapshot();
|
|
91
99
|
if (!interaction.dragSession) {
|
|
92
100
|
// No active drag session, so nothing to do on pointer cancel
|
|
@@ -95,10 +103,3 @@ export function handlePointerCancel(state, event) {
|
|
|
95
103
|
// Cancel the active interaction on pointer cancel
|
|
96
104
|
state.surface.cancelActiveInteraction();
|
|
97
105
|
}
|
|
98
|
-
export function handlePointerLeave(state, event) {
|
|
99
|
-
assert(event.type === 'pointerleave', 'handlePointerLeave should only be called for pointerleave events');
|
|
100
|
-
const interaction = state.surface.getInteractionStateSnapshot();
|
|
101
|
-
if (interaction.dragSession) {
|
|
102
|
-
state.surface.updateDragSessionCurrentTarget(event.target);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { InteractionControllerInternal } from './types';
|
|
3
|
-
export declare function transmitTransientInput(state: InteractionControllerInternal,
|
|
1
|
+
import { ExtensionOnEventContext } from '../../../extensions/types/context/events.js';
|
|
2
|
+
import { InteractionControllerInternal } from './types.js';
|
|
3
|
+
export declare function transmitTransientInput(state: InteractionControllerInternal, context: ExtensionOnEventContext): void;
|
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
function isPointerEvent(event) {
|
|
2
2
|
return event.type.startsWith('pointer');
|
|
3
3
|
}
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
function isRawPointerEvent(event) {
|
|
5
|
+
return event instanceof PointerEvent;
|
|
6
|
+
}
|
|
7
|
+
export function transmitTransientInput(state, context) {
|
|
8
|
+
if (context.sceneEvent &&
|
|
9
|
+
isPointerEvent(context.sceneEvent) &&
|
|
10
|
+
isRawPointerEvent(context.rawEvent) &&
|
|
11
|
+
context.sceneEvent.boardClampedPoint) {
|
|
6
12
|
state.surface.transientInput({
|
|
7
|
-
target:
|
|
8
|
-
|
|
9
|
-
clampedPoint:
|
|
13
|
+
target: context.sceneEvent.targetSquare,
|
|
14
|
+
point: context.sceneEvent.point,
|
|
15
|
+
clampedPoint: context.sceneEvent.clampedPoint,
|
|
16
|
+
boardClampedPoint: context.sceneEvent.boardClampedPoint
|
|
10
17
|
});
|
|
11
18
|
}
|
|
12
19
|
}
|
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { PieceCode, Square } from '../../../state/board/types/internal';
|
|
4
|
-
import { InteractionStateSnapshot } from '../../../state/interaction/types/main';
|
|
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';
|
|
5
5
|
export interface RuntimeInteractionSurface {
|
|
6
6
|
getInteractionStateSnapshot(): InteractionStateSnapshot;
|
|
7
7
|
getPieceCodeAt(square: Square): PieceCode;
|
|
8
8
|
startLiftedDrag(source: Square, target: Square): void;
|
|
9
|
-
dropTo(target: Square): void;
|
|
10
9
|
startReleaseTargetingDrag(source: Square, target: Square): void;
|
|
11
|
-
|
|
10
|
+
completeCoreDragTo(target: Square): void;
|
|
11
|
+
completeExtensionDrag(target: Square | null): void;
|
|
12
12
|
updateDragSessionCurrentTarget(target: Square | null): void;
|
|
13
13
|
cancelActiveInteraction(): void;
|
|
14
14
|
cancelInteraction(): void;
|
|
15
15
|
transientInput(input: TransientInput): void;
|
|
16
|
+
onEvent(context: ExtensionOnEventContext): void;
|
|
16
17
|
}
|
|
17
18
|
export interface InteractionControllerInternal {
|
|
18
19
|
readonly surface: RuntimeInteractionSurface;
|
|
@@ -21,5 +22,5 @@ export interface InteractionControllerInitOptions {
|
|
|
21
22
|
surface: RuntimeInteractionSurface;
|
|
22
23
|
}
|
|
23
24
|
export interface InteractionController {
|
|
24
|
-
onEvent(
|
|
25
|
+
onEvent(context: ExtensionOnEventContext): void;
|
|
25
26
|
}
|
package/dist/runtime/layout.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { RuntimeInternal } from './types/main';
|
|
1
|
+
import { RuntimeInternal } from './types/main.js';
|
|
2
2
|
export declare function runtimeRefreshGeometry(state: RuntimeInternal): void;
|
package/dist/runtime/layout.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { runtimeValidateIsMounted } from './lifecycle';
|
|
2
|
-
import { runtimeRunMutationPipeline } from './mutation/run';
|
|
1
|
+
import { runtimeValidateIsMounted } from './lifecycle.js';
|
|
2
|
+
import { runtimeRunMutationPipeline } from './mutation/run.js';
|
|
3
3
|
export function runtimeRefreshGeometry(state) {
|
|
4
4
|
runtimeValidateIsMounted(state);
|
|
5
5
|
state.layout.refreshGeometry({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { RenderSystem } from '../render/types';
|
|
2
|
-
import { RuntimeInternal } from './types/main';
|
|
1
|
+
import { RenderSystem } from '../render/types.js';
|
|
2
|
+
import { RuntimeInternal } from './types/main.js';
|
|
3
3
|
export declare function runtimeIsMounted(state: RuntimeInternal): boolean;
|
|
4
4
|
export declare function runtimeValidateIsMounted(state: RuntimeInternal): asserts state is RuntimeInternal & {
|
|
5
5
|
readonly renderSystem: RuntimeInternal['renderSystem'] & {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import assert from '@ktarmyshov/assert';
|
|
2
|
-
import { createInputAdapter } from './input/adapter/factory';
|
|
3
|
-
import { runtimeRefreshGeometry } from './layout';
|
|
2
|
+
import { createInputAdapter } from './input/adapter/factory.js';
|
|
3
|
+
import { runtimeRefreshGeometry } from './layout.js';
|
|
4
4
|
export function runtimeIsMounted(state) {
|
|
5
5
|
return state.renderSystem.isMounted;
|
|
6
6
|
}
|
|
@@ -16,18 +16,18 @@ export function runtimeValidateIsNotMounted(state) {
|
|
|
16
16
|
}
|
|
17
17
|
export function runtimeMount(state, container) {
|
|
18
18
|
runtimeValidateIsNotMounted(state);
|
|
19
|
+
assert(state.inputAdapter === null, 'Input adapter should not be initialized before mounting');
|
|
20
|
+
state.inputAdapter = createInputAdapter({
|
|
21
|
+
container,
|
|
22
|
+
getRenderGeometry: () => state.layout.geometry,
|
|
23
|
+
controller: state.interactionController
|
|
24
|
+
});
|
|
19
25
|
state.renderSystem.mount(container);
|
|
20
26
|
state.resizeObserver = new ResizeObserver(() => {
|
|
21
27
|
runtimeRefreshGeometry(state);
|
|
22
28
|
});
|
|
23
29
|
// Observe will cause immediate first callback!
|
|
24
30
|
state.resizeObserver.observe(container);
|
|
25
|
-
assert(state.inputAdapter === null, 'Input adapter should not be initialized before mounting');
|
|
26
|
-
state.inputAdapter = createInputAdapter({
|
|
27
|
-
container,
|
|
28
|
-
getGeometry: () => state.layout.geometry,
|
|
29
|
-
controller: state.interactionController
|
|
30
|
-
});
|
|
31
31
|
}
|
|
32
32
|
export function runtimeUnmount(state) {
|
|
33
33
|
runtimeValidateIsMounted(state);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { RuntimeMutationPipe } from './pipeline';
|
|
1
|
+
import { RuntimeMutationPipe } from './pipeline.js';
|
|
2
2
|
export declare const extensionSystemUpdatePipe: RuntimeMutationPipe;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { RuntimeMutationPipeline } from './pipeline';
|
|
1
|
+
import { RuntimeMutationPipeline } from './pipeline.js';
|
|
2
2
|
export declare function createRuntimeMutationPipeline(): RuntimeMutationPipeline;
|