@mirasen/chessboard 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/LICENSE +21 -0
- package/README.md +96 -0
- package/assets/pieces/chessnut/ATTRIBUTION.md +13 -0
- package/assets/pieces/chessnut/LICENSE.txt +202 -0
- package/assets/pieces/chessnut/bB.svg +58 -0
- package/assets/pieces/chessnut/bK.svg +51 -0
- package/assets/pieces/chessnut/bN.svg +19 -0
- package/assets/pieces/chessnut/bP.svg +17 -0
- package/assets/pieces/chessnut/bQ.svg +97 -0
- package/assets/pieces/chessnut/bR.svg +34 -0
- package/assets/pieces/chessnut/wB.svg +61 -0
- package/assets/pieces/chessnut/wK.svg +71 -0
- package/assets/pieces/chessnut/wN.svg +19 -0
- package/assets/pieces/chessnut/wP.svg +17 -0
- package/assets/pieces/chessnut/wQ.svg +40 -0
- package/assets/pieces/chessnut/wR.svg +38 -0
- package/dist/animation/planner.d.ts +6 -0
- package/dist/animation/planner.js +128 -0
- package/dist/animation/render/fade.d.ts +7 -0
- package/dist/animation/render/fade.js +24 -0
- package/dist/animation/render/move.d.ts +7 -0
- package/dist/animation/render/move.js +28 -0
- package/dist/animation/render/plan.d.ts +14 -0
- package/dist/animation/render/plan.js +69 -0
- package/dist/animation/render/static.d.ts +7 -0
- package/dist/animation/render/static.js +21 -0
- package/dist/animation/render/types.d.ts +21 -0
- package/dist/animation/render/types.js +1 -0
- package/dist/animation/types.d.ts +46 -0
- package/dist/animation/types.js +6 -0
- package/dist/extensions/animation/factory.d.ts +3 -0
- package/dist/extensions/animation/factory.js +88 -0
- package/dist/extensions/animation/types.d.ts +11 -0
- package/dist/extensions/animation/types.js +1 -0
- package/dist/extensions/factory/main.d.ts +2 -0
- package/dist/extensions/factory/main.js +101 -0
- package/dist/extensions/factory/runtime.d.ts +5 -0
- package/dist/extensions/factory/runtime.js +43 -0
- package/dist/extensions/first-party/active-target/factory.d.ts +2 -0
- package/dist/extensions/first-party/active-target/factory.js +109 -0
- package/dist/extensions/first-party/active-target/types.d.ts +25 -0
- package/dist/extensions/first-party/active-target/types.js +15 -0
- package/dist/extensions/first-party/board-events/factory.d.ts +2 -0
- package/dist/extensions/first-party/board-events/factory.js +65 -0
- package/dist/extensions/first-party/board-events/types.d.ts +27 -0
- package/dist/extensions/first-party/board-events/types.js +2 -0
- package/dist/extensions/first-party/common/helpers.d.ts +8 -0
- package/dist/extensions/first-party/common/helpers.js +33 -0
- package/dist/extensions/first-party/common/types.d.ts +10 -0
- package/dist/extensions/first-party/common/types.js +1 -0
- package/dist/extensions/first-party/last-move/factory.d.ts +2 -0
- package/dist/extensions/first-party/last-move/factory.js +106 -0
- package/dist/extensions/first-party/last-move/types.d.ts +19 -0
- package/dist/extensions/first-party/last-move/types.js +6 -0
- package/dist/extensions/first-party/legal-moves/factory.d.ts +2 -0
- package/dist/extensions/first-party/legal-moves/factory.js +101 -0
- package/dist/extensions/first-party/legal-moves/types.d.ts +29 -0
- package/dist/extensions/first-party/legal-moves/types.js +19 -0
- package/dist/extensions/first-party/main-renderer/animation/factory.d.ts +4 -0
- package/dist/extensions/first-party/main-renderer/animation/factory.js +35 -0
- package/dist/extensions/first-party/main-renderer/animation/render.d.ts +7 -0
- package/dist/extensions/first-party/main-renderer/animation/render.js +46 -0
- package/dist/extensions/first-party/main-renderer/animation/types.d.ts +24 -0
- package/dist/extensions/first-party/main-renderer/animation/types.js +1 -0
- package/dist/extensions/first-party/main-renderer/animation/update.d.ts +3 -0
- package/dist/extensions/first-party/main-renderer/animation/update.js +40 -0
- package/dist/extensions/first-party/main-renderer/board/factory.d.ts +3 -0
- package/dist/extensions/first-party/main-renderer/board/factory.js +16 -0
- package/dist/extensions/first-party/main-renderer/board/render.d.ts +3 -0
- package/dist/extensions/first-party/main-renderer/board/render.js +24 -0
- package/dist/extensions/first-party/main-renderer/board/types.d.ts +10 -0
- package/dist/extensions/first-party/main-renderer/board/types.js +1 -0
- package/dist/extensions/first-party/main-renderer/board/update.d.ts +3 -0
- package/dist/extensions/first-party/main-renderer/board/update.js +27 -0
- package/dist/extensions/first-party/main-renderer/coordinates/factory.d.ts +3 -0
- package/dist/extensions/first-party/main-renderer/coordinates/factory.js +9 -0
- package/dist/extensions/first-party/main-renderer/coordinates/render.d.ts +3 -0
- package/dist/extensions/first-party/main-renderer/coordinates/render.js +60 -0
- package/dist/extensions/first-party/main-renderer/coordinates/types.d.ts +8 -0
- package/dist/extensions/first-party/main-renderer/coordinates/types.js +1 -0
- package/dist/extensions/first-party/main-renderer/drag/factory.d.ts +4 -0
- package/dist/extensions/first-party/main-renderer/drag/factory.js +23 -0
- package/dist/extensions/first-party/main-renderer/drag/render.d.ts +3 -0
- package/dist/extensions/first-party/main-renderer/drag/render.js +27 -0
- package/dist/extensions/first-party/main-renderer/drag/types.d.ts +16 -0
- package/dist/extensions/first-party/main-renderer/drag/types.js +1 -0
- package/dist/extensions/first-party/main-renderer/drag/update.d.ts +3 -0
- package/dist/extensions/first-party/main-renderer/drag/update.js +23 -0
- package/dist/extensions/first-party/main-renderer/factory.d.ts +2 -0
- package/dist/extensions/first-party/main-renderer/factory.js +95 -0
- package/dist/extensions/first-party/main-renderer/normalize.d.ts +4 -0
- package/dist/extensions/first-party/main-renderer/normalize.js +27 -0
- package/dist/extensions/first-party/main-renderer/pieces/factory.d.ts +3 -0
- package/dist/extensions/first-party/main-renderer/pieces/factory.js +27 -0
- package/dist/extensions/first-party/main-renderer/pieces/render.d.ts +3 -0
- package/dist/extensions/first-party/main-renderer/pieces/render.js +45 -0
- package/dist/extensions/first-party/main-renderer/pieces/suppress.d.ts +5 -0
- package/dist/extensions/first-party/main-renderer/pieces/suppress.js +9 -0
- package/dist/extensions/first-party/main-renderer/pieces/types.d.ts +20 -0
- package/dist/extensions/first-party/main-renderer/pieces/types.js +1 -0
- package/dist/extensions/first-party/main-renderer/pieces/update.d.ts +6 -0
- package/dist/extensions/first-party/main-renderer/pieces/update.js +31 -0
- package/dist/extensions/first-party/main-renderer/types/extension.d.ts +15 -0
- package/dist/extensions/first-party/main-renderer/types/extension.js +10 -0
- package/dist/extensions/first-party/main-renderer/types/input.d.ts +4 -0
- package/dist/extensions/first-party/main-renderer/types/input.js +1 -0
- package/dist/extensions/first-party/main-renderer/types/instance.d.ts +16 -0
- package/dist/extensions/first-party/main-renderer/types/instance.js +1 -0
- package/dist/extensions/first-party/main-renderer/types/internal.d.ts +17 -0
- package/dist/extensions/first-party/main-renderer/types/internal.js +30 -0
- package/dist/extensions/first-party/main-renderer/types/template.d.ts +5 -0
- package/dist/extensions/first-party/main-renderer/types/template.js +1 -0
- package/dist/extensions/first-party/selected-square/factory.d.ts +2 -0
- package/dist/extensions/first-party/selected-square/factory.js +88 -0
- package/dist/extensions/first-party/selected-square/types.d.ts +18 -0
- package/dist/extensions/first-party/selected-square/types.js +6 -0
- package/dist/extensions/index.d.ts +8 -0
- package/dist/extensions/index.js +6 -0
- package/dist/extensions/invalidation/factory.d.ts +2 -0
- package/dist/extensions/invalidation/factory.js +22 -0
- package/dist/extensions/invalidation/types.d.ts +11 -0
- package/dist/extensions/invalidation/types.js +1 -0
- package/dist/extensions/types/basic/animation.d.ts +28 -0
- package/dist/extensions/types/basic/animation.js +6 -0
- package/dist/extensions/types/basic/events.d.ts +34 -0
- package/dist/extensions/types/basic/events.js +7 -0
- package/dist/extensions/types/basic/mount.d.ts +7 -0
- package/dist/extensions/types/basic/mount.js +14 -0
- package/dist/extensions/types/basic/render.d.ts +9 -0
- package/dist/extensions/types/basic/render.js +1 -0
- package/dist/extensions/types/basic/transient-visuals.d.ts +10 -0
- package/dist/extensions/types/basic/transient-visuals.js +1 -0
- package/dist/extensions/types/basic/update.d.ts +16 -0
- package/dist/extensions/types/basic/update.js +11 -0
- package/dist/extensions/types/context/animation.d.ts +31 -0
- package/dist/extensions/types/context/animation.js +9 -0
- package/dist/extensions/types/context/render.d.ts +6 -0
- package/dist/extensions/types/context/render.js +1 -0
- package/dist/extensions/types/context/transient-visuals.d.ts +7 -0
- package/dist/extensions/types/context/transient-visuals.js +1 -0
- package/dist/extensions/types/context/ui-move.d.ts +16 -0
- package/dist/extensions/types/context/ui-move.js +1 -0
- package/dist/extensions/types/context/update.d.ts +25 -0
- package/dist/extensions/types/context/update.js +10 -0
- package/dist/extensions/types/extension.d.ts +40 -0
- package/dist/extensions/types/extension.js +1 -0
- package/dist/extensions/types/main.d.ts +44 -0
- package/dist/extensions/types/main.js +1 -0
- package/dist/extensions/types/surface/commands.d.ts +26 -0
- package/dist/extensions/types/surface/commands.js +1 -0
- package/dist/extensions/types/surface/events.d.ts +5 -0
- package/dist/extensions/types/surface/events.js +1 -0
- package/dist/extensions/types/surface/main.d.ts +10 -0
- package/dist/extensions/types/surface/main.js +1 -0
- package/dist/extensions/types/surface/transient-visuals.d.ts +4 -0
- package/dist/extensions/types/surface/transient-visuals.js +1 -0
- package/dist/extensions/types/wrapper.d.ts +26 -0
- package/dist/extensions/types/wrapper.js +11 -0
- package/dist/extensions/update.d.ts +4 -0
- package/dist/extensions/update.js +29 -0
- package/dist/helpers/util.d.ts +1 -0
- package/dist/helpers/util.js +9 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +1 -0
- package/dist/layout/factory.d.ts +2 -0
- package/dist/layout/factory.js +33 -0
- package/dist/layout/geometry/factory.d.ts +12 -0
- package/dist/layout/geometry/factory.js +33 -0
- package/dist/layout/geometry/types.d.ts +20 -0
- package/dist/layout/geometry/types.js +1 -0
- package/dist/layout/helpers.d.ts +4 -0
- package/dist/layout/helpers.js +6 -0
- package/dist/layout/mutation.d.ts +6 -0
- package/dist/layout/mutation.js +1 -0
- package/dist/layout/reducers.d.ts +2 -0
- package/dist/layout/reducers.js +30 -0
- package/dist/layout/types.d.ts +23 -0
- package/dist/layout/types.js +1 -0
- package/dist/mutation/pipeline.d.ts +2 -0
- package/dist/mutation/pipeline.js +36 -0
- package/dist/mutation/session.d.ts +3 -0
- package/dist/mutation/session.js +66 -0
- package/dist/mutation/types.d.ts +26 -0
- package/dist/mutation/types.js +1 -0
- package/dist/render/factory.d.ts +2 -0
- package/dist/render/factory.js +117 -0
- package/dist/render/mount.d.ts +3 -0
- package/dist/render/mount.js +28 -0
- package/dist/render/rendering/animation.d.ts +13 -0
- package/dist/render/rendering/animation.js +92 -0
- package/dist/render/rendering/helpers.d.ts +3 -0
- package/dist/render/rendering/helpers.js +10 -0
- package/dist/render/rendering/state.d.ts +4 -0
- package/dist/render/rendering/state.js +48 -0
- package/dist/render/rendering/visuals.d.ts +3 -0
- package/dist/render/rendering/visuals.js +21 -0
- package/dist/render/scheduler/scheduler.d.ts +2 -0
- package/dist/render/scheduler/scheduler.js +53 -0
- package/dist/render/scheduler/types.d.ts +12 -0
- package/dist/render/scheduler/types.js +1 -0
- package/dist/render/svg/factory.d.ts +4 -0
- package/dist/render/svg/factory.js +38 -0
- package/dist/render/svg/helpers.d.ts +18 -0
- package/dist/render/svg/helpers.js +34 -0
- package/dist/render/types.d.ts +42 -0
- package/dist/render/types.js +1 -0
- package/dist/runtime/factory/helpers.d.ts +6 -0
- package/dist/runtime/factory/helpers.js +42 -0
- package/dist/runtime/factory/input.d.ts +3 -0
- package/dist/runtime/factory/input.js +98 -0
- package/dist/runtime/factory/main.d.ts +2 -0
- package/dist/runtime/factory/main.js +182 -0
- package/dist/runtime/factory/ui-move.d.ts +4 -0
- package/dist/runtime/factory/ui-move.js +84 -0
- package/dist/runtime/input/adapter/factory.d.ts +2 -0
- package/dist/runtime/input/adapter/factory.js +55 -0
- package/dist/runtime/input/adapter/helpers.d.ts +5 -0
- package/dist/runtime/input/adapter/helpers.js +23 -0
- package/dist/runtime/input/adapter/pointer.d.ts +13 -0
- package/dist/runtime/input/adapter/pointer.js +97 -0
- package/dist/runtime/input/adapter/types.d.ts +16 -0
- package/dist/runtime/input/adapter/types.js +1 -0
- package/dist/runtime/input/controller/factory.d.ts +2 -0
- package/dist/runtime/input/controller/factory.js +32 -0
- package/dist/runtime/input/controller/helpers.d.ts +3 -0
- package/dist/runtime/input/controller/helpers.js +12 -0
- package/dist/runtime/input/controller/pointer.d.ts +7 -0
- package/dist/runtime/input/controller/pointer.js +104 -0
- package/dist/runtime/input/controller/transient-visuals.d.ts +3 -0
- package/dist/runtime/input/controller/transient-visuals.js +12 -0
- package/dist/runtime/input/controller/types.d.ts +25 -0
- package/dist/runtime/input/controller/types.js +1 -0
- package/dist/runtime/layout.d.ts +2 -0
- package/dist/runtime/layout.js +10 -0
- package/dist/runtime/lifecycle.d.ts +12 -0
- package/dist/runtime/lifecycle.js +49 -0
- package/dist/runtime/mutation/extension-update.d.ts +2 -0
- package/dist/runtime/mutation/extension-update.js +26 -0
- package/dist/runtime/mutation/factory.d.ts +2 -0
- package/dist/runtime/mutation/factory.js +47 -0
- package/dist/runtime/mutation/interaction.d.ts +2 -0
- package/dist/runtime/mutation/interaction.js +34 -0
- package/dist/runtime/mutation/invalidation.d.ts +0 -0
- package/dist/runtime/mutation/invalidation.js +2 -0
- package/dist/runtime/mutation/last-move.d.ts +3 -0
- package/dist/runtime/mutation/last-move.js +19 -0
- package/dist/runtime/mutation/layout.d.ts +2 -0
- package/dist/runtime/mutation/layout.js +8 -0
- package/dist/runtime/mutation/pipeline.d.ts +22 -0
- package/dist/runtime/mutation/pipeline.js +1 -0
- package/dist/runtime/mutation/request-render.d.ts +2 -0
- package/dist/runtime/mutation/request-render.js +29 -0
- package/dist/runtime/mutation/run.d.ts +2 -0
- package/dist/runtime/mutation/run.js +3 -0
- package/dist/runtime/mutation/types.d.ts +14 -0
- package/dist/runtime/mutation/types.js +1 -0
- package/dist/runtime/types/main.d.ts +36 -0
- package/dist/runtime/types/main.js +1 -0
- package/dist/runtime/types/ui-move.d.ts +9 -0
- package/dist/runtime/types/ui-move.js +1 -0
- package/dist/state/board/check.d.ts +27 -0
- package/dist/state/board/check.js +148 -0
- package/dist/state/board/coords.d.ts +4 -0
- package/dist/state/board/coords.js +9 -0
- package/dist/state/board/denormalize.d.ts +11 -0
- package/dist/state/board/denormalize.js +77 -0
- package/dist/state/board/factory.d.ts +3 -0
- package/dist/state/board/factory.js +46 -0
- package/dist/state/board/mutation.d.ts +9 -0
- package/dist/state/board/mutation.js +1 -0
- package/dist/state/board/normalize.d.ts +8 -0
- package/dist/state/board/normalize.js +76 -0
- package/dist/state/board/piece.d.ts +3 -0
- package/dist/state/board/piece.js +11 -0
- package/dist/state/board/position.d.ts +4 -0
- package/dist/state/board/position.js +94 -0
- package/dist/state/board/reducers.d.ts +8 -0
- package/dist/state/board/reducers.js +80 -0
- package/dist/state/board/types/input.d.ts +35 -0
- package/dist/state/board/types/input.js +1 -0
- package/dist/state/board/types/internal.d.ts +54 -0
- package/dist/state/board/types/internal.js +17 -0
- package/dist/state/board/types/main.d.ts +18 -0
- package/dist/state/board/types/main.js +1 -0
- package/dist/state/board/types/output.d.ts +5 -0
- package/dist/state/board/types/output.js +1 -0
- package/dist/state/board/types/template.d.ts +23 -0
- package/dist/state/board/types/template.js +1 -0
- package/dist/state/change/factory.d.ts +2 -0
- package/dist/state/change/factory.js +28 -0
- package/dist/state/change/helpers.d.ts +8 -0
- package/dist/state/change/helpers.js +86 -0
- package/dist/state/change/mutation.d.ts +6 -0
- package/dist/state/change/mutation.js +1 -0
- package/dist/state/change/reducers.d.ts +5 -0
- package/dist/state/change/reducers.js +16 -0
- package/dist/state/change/types.d.ts +17 -0
- package/dist/state/change/types.js +1 -0
- package/dist/state/factory.d.ts +2 -0
- package/dist/state/factory.js +24 -0
- package/dist/state/interaction/factory.d.ts +2 -0
- package/dist/state/interaction/factory.js +83 -0
- package/dist/state/interaction/helpers.d.ts +4 -0
- package/dist/state/interaction/helpers.js +16 -0
- package/dist/state/interaction/movability.d.ts +5 -0
- package/dist/state/interaction/movability.js +87 -0
- package/dist/state/interaction/mutation.d.ts +11 -0
- package/dist/state/interaction/mutation.js +1 -0
- package/dist/state/interaction/normalize.d.ts +5 -0
- package/dist/state/interaction/normalize.js +50 -0
- package/dist/state/interaction/reducers.d.ts +11 -0
- package/dist/state/interaction/reducers.js +81 -0
- package/dist/state/interaction/types/input.d.ts +18 -0
- package/dist/state/interaction/types/input.js +1 -0
- package/dist/state/interaction/types/internal.d.ts +35 -0
- package/dist/state/interaction/types/internal.js +1 -0
- package/dist/state/interaction/types/main.d.ts +33 -0
- package/dist/state/interaction/types/main.js +1 -0
- package/dist/state/types.d.ts +30 -0
- package/dist/state/types.js +1 -0
- package/dist/state/view/factory.d.ts +2 -0
- package/dist/state/view/factory.js +24 -0
- package/dist/state/view/mutation.d.ts +5 -0
- package/dist/state/view/mutation.js +1 -0
- package/dist/state/view/reducers.d.ts +3 -0
- package/dist/state/view/reducers.js +6 -0
- package/dist/state/view/types/internal.d.ts +6 -0
- package/dist/state/view/types/internal.js +1 -0
- package/dist/state/view/types/main.d.ts +12 -0
- package/dist/state/view/types/main.js +1 -0
- package/dist/wrapper/factory.d.ts +3 -0
- package/dist/wrapper/factory.js +61 -0
- package/dist/wrapper/types.d.ts +56 -0
- package/dist/wrapper/types.js +1 -0
- package/package.json +98 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ExtensionRenderContext } from '../../../types/context/render';
|
|
2
|
+
import { ConfigColorPair } from '../types/internal';
|
|
3
|
+
export interface MainRendererCoordinatesInternal {
|
|
4
|
+
readonly config: ConfigColorPair;
|
|
5
|
+
}
|
|
6
|
+
export interface MainRendererCoordinates {
|
|
7
|
+
render(context: ExtensionRenderContext, layer: SVGElement): void;
|
|
8
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ExtensionRuntimeSurface } from '../../../types/surface/main';
|
|
2
|
+
import { PieceUrls } from '../types/internal';
|
|
3
|
+
import { MainRendererDrag } from './types';
|
|
4
|
+
export declare function createMainRendererDrag(config: PieceUrls, runtimeSurface: ExtensionRuntimeSurface): MainRendererDrag;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { rendererDragRenderTransientVisuals } from './render';
|
|
2
|
+
import { rendererDragOnUpdate } from './update';
|
|
3
|
+
function createMainRendererDragInternal(config, runtimeSurface) {
|
|
4
|
+
return { config, runtimeSurface, isDragActive: false, pieceUrl: null, pieceNode: null };
|
|
5
|
+
}
|
|
6
|
+
export function createMainRendererDrag(config, runtimeSurface) {
|
|
7
|
+
const internalState = createMainRendererDragInternal(config, runtimeSurface);
|
|
8
|
+
return {
|
|
9
|
+
onUpdate(context) {
|
|
10
|
+
rendererDragOnUpdate(internalState, context);
|
|
11
|
+
},
|
|
12
|
+
renderTransientVisuals(context, layer) {
|
|
13
|
+
rendererDragRenderTransientVisuals(internalState, context, layer);
|
|
14
|
+
},
|
|
15
|
+
unmount() {
|
|
16
|
+
internalState.pieceNode?.remove();
|
|
17
|
+
internalState.pieceNode = null;
|
|
18
|
+
internalState.pieceUrl = null;
|
|
19
|
+
internalState.isDragActive = false;
|
|
20
|
+
internalState.runtimeSurface.transientVisuals.unsubscribe();
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { ExtensionRenderTransientVisualsContext } from '../../../types/context/transient-visuals';
|
|
2
|
+
import { MainRendererDragInternal } from './types';
|
|
3
|
+
export declare function rendererDragRenderTransientVisuals(state: MainRendererDragInternal, context: ExtensionRenderTransientVisualsContext, layer: SVGElement): void;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { createSvgElement, updateElementAttributes } from '../../../../render/svg/helpers';
|
|
2
|
+
export function rendererDragRenderTransientVisuals(state, context, layer) {
|
|
3
|
+
const geometry = context.currentFrame.layout.geometry;
|
|
4
|
+
const point = context.transientInput.clampedPoint;
|
|
5
|
+
const squareSize = geometry.squareSize.toString();
|
|
6
|
+
const x = (point.x - geometry.squareSize / 2).toString();
|
|
7
|
+
const y = (point.y - geometry.squareSize / 2).toString();
|
|
8
|
+
if (state.isDragActive && state.pieceUrl && !state.pieceNode) {
|
|
9
|
+
// Ok this is first render pass, let's create the piece node
|
|
10
|
+
state.pieceNode = createSvgElement(layer, 'image', {
|
|
11
|
+
'data-chessboard-id': 'dragged-piece',
|
|
12
|
+
width: squareSize,
|
|
13
|
+
height: squareSize,
|
|
14
|
+
x,
|
|
15
|
+
y,
|
|
16
|
+
href: state.pieceUrl
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
else if (state.isDragActive && state.pieceNode) {
|
|
20
|
+
updateElementAttributes(state.pieceNode, {
|
|
21
|
+
width: squareSize,
|
|
22
|
+
height: squareSize,
|
|
23
|
+
x,
|
|
24
|
+
y
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ExtensionRenderTransientVisualsContext } from '../../../types/context/transient-visuals';
|
|
2
|
+
import { ExtensionUpdateContext } from '../../../types/context/update';
|
|
3
|
+
import { ExtensionRuntimeSurface } from '../../../types/surface/main';
|
|
4
|
+
import { PieceUrls } from '../types/internal';
|
|
5
|
+
export interface MainRendererDragInternal {
|
|
6
|
+
readonly config: PieceUrls;
|
|
7
|
+
readonly runtimeSurface: ExtensionRuntimeSurface;
|
|
8
|
+
isDragActive: boolean;
|
|
9
|
+
pieceUrl: string | null;
|
|
10
|
+
pieceNode: SVGImageElement | null;
|
|
11
|
+
}
|
|
12
|
+
export interface MainRendererDrag {
|
|
13
|
+
onUpdate(context: ExtensionUpdateContext): void;
|
|
14
|
+
renderTransientVisuals(context: ExtensionRenderTransientVisualsContext, layer: SVGElement): void;
|
|
15
|
+
unmount(): void;
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import assert from '@ktarmyshov/assert';
|
|
2
|
+
import { isNonEmptyPieceCode } from '../../../../state/board/check';
|
|
3
|
+
export function rendererDragOnUpdate(state, context) {
|
|
4
|
+
const isLiftedDragActive = context.currentFrame.state.interaction.dragSession?.type === 'lifted-piece-drag';
|
|
5
|
+
if (isLiftedDragActive) {
|
|
6
|
+
if (!state.isDragActive) {
|
|
7
|
+
const pieceCode = context.currentFrame.state.interaction.dragSession.sourcePieceCode;
|
|
8
|
+
assert(isNonEmptyPieceCode(pieceCode), 'Invalid piece code in drag session');
|
|
9
|
+
state.pieceUrl = state.config[pieceCode];
|
|
10
|
+
state.runtimeSurface.transientVisuals.subscribe();
|
|
11
|
+
}
|
|
12
|
+
state.isDragActive = true;
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
if (state.isDragActive) {
|
|
16
|
+
state.runtimeSurface.transientVisuals.unsubscribe();
|
|
17
|
+
state.pieceNode?.remove();
|
|
18
|
+
state.pieceNode = null;
|
|
19
|
+
state.pieceUrl = null;
|
|
20
|
+
}
|
|
21
|
+
state.isDragActive = false;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { toMerged } from 'es-toolkit';
|
|
2
|
+
import { extensionCreateInternalBase, extensionDestroy, extensionMount, extensionUnmount } from '../common/helpers';
|
|
3
|
+
import { createMainRendererAnimation } from './animation/factory';
|
|
4
|
+
import { createMainRendererBoard } from './board/factory';
|
|
5
|
+
import { createMainRendererCoordinates } from './coordinates/factory';
|
|
6
|
+
import { createMainRendererDrag } from './drag/factory';
|
|
7
|
+
import { normalizeMainRendererConfig } from './normalize';
|
|
8
|
+
import { createMainRendererPieces } from './pieces/factory';
|
|
9
|
+
import { EXTENSION_ID, EXTENSION_SLOTS } from './types/extension';
|
|
10
|
+
import { DEFAULT_MAIN_RENDERER_CONFIG } from './types/internal';
|
|
11
|
+
export function createMainRenderer(options = {}) {
|
|
12
|
+
const config = toMerged(DEFAULT_MAIN_RENDERER_CONFIG, normalizeMainRendererConfig(options));
|
|
13
|
+
return {
|
|
14
|
+
id: EXTENSION_ID,
|
|
15
|
+
slots: EXTENSION_SLOTS,
|
|
16
|
+
createInstance(options) {
|
|
17
|
+
return createMainRendererInstance(options, config);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function createMainRendererInternal(options, config) {
|
|
22
|
+
const board = createMainRendererBoard(config.colors.board);
|
|
23
|
+
const coordinates = createMainRendererCoordinates(config.colors.coordinates);
|
|
24
|
+
const pieces = createMainRendererPieces(config.pieceUrls);
|
|
25
|
+
const drag = createMainRendererDrag(config.pieceUrls, options.runtimeSurface);
|
|
26
|
+
const animation = createMainRendererAnimation(config.pieceUrls, options.runtimeSurface);
|
|
27
|
+
return {
|
|
28
|
+
...extensionCreateInternalBase(),
|
|
29
|
+
board,
|
|
30
|
+
coordinates,
|
|
31
|
+
pieces,
|
|
32
|
+
drag,
|
|
33
|
+
animation,
|
|
34
|
+
runtimeSurface: options.runtimeSurface
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function extensionUnmountLocal(state) {
|
|
38
|
+
// internalState.board.unmount();
|
|
39
|
+
// internalState.coordinates.unmount();
|
|
40
|
+
state.pieces.unmount();
|
|
41
|
+
state.drag.unmount();
|
|
42
|
+
state.animation.unmount();
|
|
43
|
+
}
|
|
44
|
+
function validateIsMounted(state) {
|
|
45
|
+
if (state.slotRoots === null) {
|
|
46
|
+
throw new Error('Extension instance is not mounted yet');
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function createMainRendererInstance(options, config) {
|
|
50
|
+
const internalState = createMainRendererInternal(options, config);
|
|
51
|
+
return {
|
|
52
|
+
id: EXTENSION_ID,
|
|
53
|
+
mount(env) {
|
|
54
|
+
extensionMount(internalState, env.slotRoots);
|
|
55
|
+
},
|
|
56
|
+
onUpdate(context) {
|
|
57
|
+
internalState.board.onUpdate(context);
|
|
58
|
+
internalState.animation.onUpdate(context);
|
|
59
|
+
internalState.pieces.onUpdate(context, internalState.animation.getSuppressedSquares());
|
|
60
|
+
internalState.drag.onUpdate(context);
|
|
61
|
+
},
|
|
62
|
+
render(context) {
|
|
63
|
+
validateIsMounted(internalState);
|
|
64
|
+
internalState.board.render(context, internalState.slotRoots.board);
|
|
65
|
+
internalState.coordinates.render(context, internalState.slotRoots.coordinates);
|
|
66
|
+
internalState.pieces.render(context, internalState.slotRoots.pieces);
|
|
67
|
+
},
|
|
68
|
+
renderTransientVisuals(context) {
|
|
69
|
+
validateIsMounted(internalState);
|
|
70
|
+
internalState.drag.renderTransientVisuals(context, internalState.slotRoots.drag);
|
|
71
|
+
},
|
|
72
|
+
prepareAnimation(context) {
|
|
73
|
+
validateIsMounted(internalState);
|
|
74
|
+
internalState.animation.prepareAnimation(context, internalState.slotRoots.animation);
|
|
75
|
+
},
|
|
76
|
+
renderAnimation(context) {
|
|
77
|
+
validateIsMounted(internalState);
|
|
78
|
+
internalState.animation.renderAnimation(context);
|
|
79
|
+
},
|
|
80
|
+
onAnimationFinished(context) {
|
|
81
|
+
internalState.pieces.refreshSuppressedSquares(context, internalState.animation.getSuppressedSquares());
|
|
82
|
+
},
|
|
83
|
+
cleanAnimation(context) {
|
|
84
|
+
internalState.animation.cleanAnimation(context);
|
|
85
|
+
},
|
|
86
|
+
unmount() {
|
|
87
|
+
extensionUnmountLocal(internalState);
|
|
88
|
+
extensionUnmount(internalState);
|
|
89
|
+
},
|
|
90
|
+
destroy() {
|
|
91
|
+
extensionUnmountLocal(internalState);
|
|
92
|
+
extensionDestroy(internalState);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { MainRendererConfigInput, PieceUrlsInput } from './types/input';
|
|
2
|
+
import { MainRendererConfig, PieceUrls } from './types/internal';
|
|
3
|
+
export declare function normalizePieceUrls(input: PieceUrlsInput): PieceUrls;
|
|
4
|
+
export declare function normalizeMainRendererConfig(input: Partial<MainRendererConfigInput>): MainRendererConfig;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import assert from '@ktarmyshov/assert';
|
|
2
|
+
import { normalizePiece } from '../../../state/board/normalize';
|
|
3
|
+
import { ALL_NON_EMPTY_PIECE_CODES } from '../../../state/board/types/internal';
|
|
4
|
+
import { DEFAULT_MAIN_RENDERER_CONFIG } from './types/internal';
|
|
5
|
+
function assertPieceUrlsComplete(pieceUrls) {
|
|
6
|
+
for (const pieceCode of ALL_NON_EMPTY_PIECE_CODES) {
|
|
7
|
+
assert(pieceCode in pieceUrls, `Missing URL for piece code: ${pieceCode}`);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export function normalizePieceUrls(input) {
|
|
11
|
+
const normalized = {};
|
|
12
|
+
for (const [key, url] of Object.entries(input)) {
|
|
13
|
+
const pieceCode = normalizePiece(key);
|
|
14
|
+
assert(pieceCode !== 0 /* PieceCode.Empty */, `Invalid piece string: ${key}`);
|
|
15
|
+
normalized[pieceCode] = url;
|
|
16
|
+
}
|
|
17
|
+
assertPieceUrlsComplete(normalized);
|
|
18
|
+
return normalized;
|
|
19
|
+
}
|
|
20
|
+
export function normalizeMainRendererConfig(input) {
|
|
21
|
+
return {
|
|
22
|
+
colors: input.colors ?? DEFAULT_MAIN_RENDERER_CONFIG.colors,
|
|
23
|
+
pieceUrls: input.pieceUrls
|
|
24
|
+
? normalizePieceUrls(input.pieceUrls)
|
|
25
|
+
: DEFAULT_MAIN_RENDERER_CONFIG.pieceUrls
|
|
26
|
+
};
|
|
27
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { rendererPiecesRender } from './render';
|
|
2
|
+
import { rendererPiecesOnUpdate, rendererPiecesRefreshSuppressedSquares } from './update';
|
|
3
|
+
export function createMainRendererPieces(config) {
|
|
4
|
+
const state = {
|
|
5
|
+
config,
|
|
6
|
+
pieceNodes: new Map(),
|
|
7
|
+
suppressedSquares: new Set()
|
|
8
|
+
};
|
|
9
|
+
return {
|
|
10
|
+
onUpdate(context, animationSuppressedSquares) {
|
|
11
|
+
rendererPiecesOnUpdate(state, context, animationSuppressedSquares);
|
|
12
|
+
},
|
|
13
|
+
refreshSuppressedSquares(context, animationSuppressedSquares) {
|
|
14
|
+
rendererPiecesRefreshSuppressedSquares(state, context, animationSuppressedSquares);
|
|
15
|
+
},
|
|
16
|
+
render(context, layer) {
|
|
17
|
+
rendererPiecesRender(state, context, layer);
|
|
18
|
+
},
|
|
19
|
+
unmount() {
|
|
20
|
+
for (const nodeRecord of state.pieceNodes.values()) {
|
|
21
|
+
nodeRecord.root.remove();
|
|
22
|
+
}
|
|
23
|
+
state.pieceNodes.clear();
|
|
24
|
+
state.suppressedSquares = new Set();
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { createSvgElement, updateElementAttributes } from '../../../../render/svg/helpers';
|
|
2
|
+
import { isNonEmptyPieceCode } from '../../../../state/board/check';
|
|
3
|
+
import { SQUARE_COUNT } from '../../../../state/board/types/internal';
|
|
4
|
+
import { DirtyLayer } from '../types/extension';
|
|
5
|
+
export function rendererPiecesRender(state, context, layer) {
|
|
6
|
+
if ((context.invalidation.dirtyLayers & DirtyLayer.Pieces) === 0) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
const geometry = context.currentFrame.layout.geometry;
|
|
10
|
+
const pieces = context.currentFrame.state.board.pieces;
|
|
11
|
+
for (let sq = 0; sq < SQUARE_COUNT; sq++) {
|
|
12
|
+
const pieceCode = pieces[sq];
|
|
13
|
+
const existing = state.pieceNodes.get(sq) || null;
|
|
14
|
+
const suppressed = state.suppressedSquares.has(sq);
|
|
15
|
+
if (isNonEmptyPieceCode(pieceCode) && !suppressed) {
|
|
16
|
+
const url = state.config[pieceCode];
|
|
17
|
+
const r = geometry.squareRect(sq);
|
|
18
|
+
if (existing !== null) {
|
|
19
|
+
updateElementAttributes(existing.root, {
|
|
20
|
+
x: r.x.toString(),
|
|
21
|
+
y: r.y.toString(),
|
|
22
|
+
width: r.size.toString(),
|
|
23
|
+
height: r.size.toString(),
|
|
24
|
+
href: url
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
state.pieceNodes.set(sq, {
|
|
29
|
+
root: createSvgElement(layer, 'image', {
|
|
30
|
+
'data-chessboard-id': `piece-${pieceCode}-${sq}`,
|
|
31
|
+
href: url,
|
|
32
|
+
x: r.x.toString(),
|
|
33
|
+
y: r.y.toString(),
|
|
34
|
+
width: r.size.toString(),
|
|
35
|
+
height: r.size.toString()
|
|
36
|
+
})
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
else if (existing !== null) {
|
|
41
|
+
layer.removeChild(existing.root);
|
|
42
|
+
state.pieceNodes.delete(sq);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Square } from '../../../../state/board/types/internal';
|
|
2
|
+
import { ExtensionCleanAnimationContext } from '../../../types/context/animation';
|
|
3
|
+
import { ExtensionUpdateContext } from '../../../types/context/update';
|
|
4
|
+
import { MainRendererPiecesInternal } from './types';
|
|
5
|
+
export declare function calculateSuppressedSquares(_state: MainRendererPiecesInternal, context: ExtensionUpdateContext | ExtensionCleanAnimationContext, animationSuppressedSquares: ReadonlySet<Square>): ReadonlySet<Square>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export function calculateSuppressedSquares(_state, context, animationSuppressedSquares) {
|
|
2
|
+
const dragSession = context.currentFrame.state.interaction.dragSession;
|
|
3
|
+
const dragSquare = dragSession?.type === 'lifted-piece-drag' ? dragSession.sourceSquare : undefined;
|
|
4
|
+
const result = new Set(animationSuppressedSquares);
|
|
5
|
+
if (dragSquare !== undefined) {
|
|
6
|
+
result.add(dragSquare);
|
|
7
|
+
}
|
|
8
|
+
return result;
|
|
9
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Square } from '../../../../state/board/types/internal';
|
|
2
|
+
import { ExtensionCleanAnimationContext } from '../../../types/context/animation';
|
|
3
|
+
import { ExtensionRenderContext } from '../../../types/context/render';
|
|
4
|
+
import { ExtensionUpdateContext } from '../../../types/context/update';
|
|
5
|
+
import { PieceUrls } from '../types/internal';
|
|
6
|
+
type PieceNodeRecord = {
|
|
7
|
+
root: SVGImageElement;
|
|
8
|
+
};
|
|
9
|
+
export interface MainRendererPiecesInternal {
|
|
10
|
+
readonly config: PieceUrls;
|
|
11
|
+
readonly pieceNodes: Map<Square, PieceNodeRecord>;
|
|
12
|
+
suppressedSquares: ReadonlySet<Square>;
|
|
13
|
+
}
|
|
14
|
+
export interface MainRendererPieces {
|
|
15
|
+
onUpdate(context: ExtensionUpdateContext, animationSuppressedSquares: ReadonlySet<Square>): void;
|
|
16
|
+
refreshSuppressedSquares(context: ExtensionCleanAnimationContext, animationSuppressedSquares: ReadonlySet<Square>): void;
|
|
17
|
+
render(context: ExtensionRenderContext, layer: SVGElement): void;
|
|
18
|
+
unmount(): void;
|
|
19
|
+
}
|
|
20
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Square } from '../../../../state/board/types/internal';
|
|
2
|
+
import { ExtensionCleanAnimationContext } from '../../../types/context/animation';
|
|
3
|
+
import { ExtensionUpdateContext } from '../../../types/context/update';
|
|
4
|
+
import { MainRendererPiecesInternal } from './types';
|
|
5
|
+
export declare function rendererPiecesOnUpdate(state: MainRendererPiecesInternal, context: ExtensionUpdateContext, animationSuppressedSquares: ReadonlySet<Square>): void;
|
|
6
|
+
export declare function rendererPiecesRefreshSuppressedSquares(state: MainRendererPiecesInternal, context: ExtensionCleanAnimationContext, animationSuppressedSquares: ReadonlySet<Square>): void;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { setsEqual } from '../../../../helpers/util';
|
|
2
|
+
import { piecePositionsEqual } from '../../../../state/board/check';
|
|
3
|
+
import { isUpdateContextRenderable } from '../../../types/context/update';
|
|
4
|
+
import { DirtyLayer } from '../types/extension';
|
|
5
|
+
import { calculateSuppressedSquares } from './suppress';
|
|
6
|
+
export function rendererPiecesOnUpdate(state, context, animationSuppressedSquares) {
|
|
7
|
+
if (!isUpdateContextRenderable(context) ||
|
|
8
|
+
!context.mutation.hasMutation({
|
|
9
|
+
prefixes: ['state.board.', 'state.interaction.'],
|
|
10
|
+
causes: ['layout.refreshGeometry']
|
|
11
|
+
})) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const previousSuppressedSquares = state.suppressedSquares;
|
|
15
|
+
state.suppressedSquares = calculateSuppressedSquares(state, context, animationSuppressedSquares);
|
|
16
|
+
const needsRender = context.mutation.hasMutation({ causes: ['layout.refreshGeometry'] }) ||
|
|
17
|
+
!context.previousFrame ||
|
|
18
|
+
!setsEqual(previousSuppressedSquares, state.suppressedSquares) ||
|
|
19
|
+
!piecePositionsEqual(context.currentFrame.state.board, context.previousFrame.state.board);
|
|
20
|
+
if (!needsRender)
|
|
21
|
+
return;
|
|
22
|
+
context.invalidation.markDirty(DirtyLayer.Pieces);
|
|
23
|
+
}
|
|
24
|
+
export function rendererPiecesRefreshSuppressedSquares(state, context, animationSuppressedSquares) {
|
|
25
|
+
const newSuppressedSquares = calculateSuppressedSquares(state, context, animationSuppressedSquares);
|
|
26
|
+
const needsRender = !setsEqual(state.suppressedSquares, newSuppressedSquares);
|
|
27
|
+
state.suppressedSquares = newSuppressedSquares;
|
|
28
|
+
if (needsRender) {
|
|
29
|
+
context.invalidation.markDirty(DirtyLayer.Pieces);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ExtensionDefinition, ExtensionInstance } from '../../../types/extension';
|
|
2
|
+
import { MainRendererConfigInput } from './input';
|
|
3
|
+
export type MainRendererInitOptions = Partial<MainRendererConfigInput>;
|
|
4
|
+
export declare const EXTENSION_SLOTS: readonly ["board", "coordinates", "pieces", "animation", "drag"];
|
|
5
|
+
export type ExtensionSlotsType = typeof EXTENSION_SLOTS;
|
|
6
|
+
export declare const EXTENSION_ID: "main-renderer";
|
|
7
|
+
export type MainRendererDefinition = ExtensionDefinition<typeof EXTENSION_ID, typeof EXTENSION_SLOTS, never>;
|
|
8
|
+
export type MainRendererInstance = ExtensionInstance<typeof EXTENSION_ID, typeof EXTENSION_SLOTS, never>;
|
|
9
|
+
export declare enum DirtyLayer {
|
|
10
|
+
Board = 1,// 1 << 0,
|
|
11
|
+
Coordinates = 2,// 1 << 1,
|
|
12
|
+
Pieces = 4,// 1 << 2,
|
|
13
|
+
Drag = 8,// 1 << 3,
|
|
14
|
+
All = 15
|
|
15
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const EXTENSION_SLOTS = ['board', 'coordinates', 'pieces', 'animation', 'drag'];
|
|
2
|
+
export const EXTENSION_ID = 'main-renderer';
|
|
3
|
+
export var DirtyLayer;
|
|
4
|
+
(function (DirtyLayer) {
|
|
5
|
+
DirtyLayer[DirtyLayer["Board"] = 1] = "Board";
|
|
6
|
+
DirtyLayer[DirtyLayer["Coordinates"] = 2] = "Coordinates";
|
|
7
|
+
DirtyLayer[DirtyLayer["Pieces"] = 4] = "Pieces";
|
|
8
|
+
DirtyLayer[DirtyLayer["Drag"] = 8] = "Drag";
|
|
9
|
+
DirtyLayer[DirtyLayer["All"] = 15] = "All";
|
|
10
|
+
})(DirtyLayer || (DirtyLayer = {}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ExtensionRuntimeSurface } from '../../../types/surface/main';
|
|
2
|
+
import { ExtensionInternal } from '../../common/types';
|
|
3
|
+
import { MainRendererAnimation } from '../animation/types';
|
|
4
|
+
import { MainRendererBoard } from '../board/types';
|
|
5
|
+
import { MainRendererCoordinates } from '../coordinates/types';
|
|
6
|
+
import { MainRendererDrag } from '../drag/types';
|
|
7
|
+
import { MainRendererPieces } from '../pieces/types';
|
|
8
|
+
import { ExtensionSlotsType } from './extension';
|
|
9
|
+
export interface MainRendererInstanceInternal extends ExtensionInternal<ExtensionSlotsType> {
|
|
10
|
+
readonly board: MainRendererBoard;
|
|
11
|
+
readonly coordinates: MainRendererCoordinates;
|
|
12
|
+
readonly pieces: MainRendererPieces;
|
|
13
|
+
readonly drag: MainRendererDrag;
|
|
14
|
+
readonly animation: MainRendererAnimation;
|
|
15
|
+
readonly runtimeSurface: ExtensionRuntimeSurface;
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { NonEmptyPieceCode } from '../../../../state/board/types/internal';
|
|
2
|
+
import { TMainRendererConfig } from './template';
|
|
3
|
+
export interface ConfigColorPair {
|
|
4
|
+
light: string;
|
|
5
|
+
dark: string;
|
|
6
|
+
}
|
|
7
|
+
export interface ConfigColors {
|
|
8
|
+
board: ConfigColorPair;
|
|
9
|
+
coordinates: ConfigColorPair;
|
|
10
|
+
}
|
|
11
|
+
export type PieceUrls = Record<NonEmptyPieceCode, string>;
|
|
12
|
+
export type MainRendererConfig = TMainRendererConfig<PieceUrls>;
|
|
13
|
+
export declare const CHESSNUT_PIECE_URLS: PieceUrls;
|
|
14
|
+
/**
|
|
15
|
+
* Default board renderer configuration.
|
|
16
|
+
*/
|
|
17
|
+
export declare const DEFAULT_MAIN_RENDERER_CONFIG: MainRendererConfig;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export const CHESSNUT_PIECE_URLS = {
|
|
2
|
+
[6 /* PieceCode.WhiteKing */]: new URL('../../../../../assets/pieces/chessnut/wK.svg', import.meta.url).toString(),
|
|
3
|
+
[5 /* PieceCode.WhiteQueen */]: new URL('../../../../../assets/pieces/chessnut/wQ.svg', import.meta.url).toString(),
|
|
4
|
+
[4 /* PieceCode.WhiteRook */]: new URL('../../../../../assets/pieces/chessnut/wR.svg', import.meta.url).toString(),
|
|
5
|
+
[3 /* PieceCode.WhiteBishop */]: new URL('../../../../../assets/pieces/chessnut/wB.svg', import.meta.url).toString(),
|
|
6
|
+
[2 /* PieceCode.WhiteKnight */]: new URL('../../../../../assets/pieces/chessnut/wN.svg', import.meta.url).toString(),
|
|
7
|
+
[1 /* PieceCode.WhitePawn */]: new URL('../../../../../assets/pieces/chessnut/wP.svg', import.meta.url).toString(),
|
|
8
|
+
[14 /* PieceCode.BlackKing */]: new URL('../../../../../assets/pieces/chessnut/bK.svg', import.meta.url).toString(),
|
|
9
|
+
[13 /* PieceCode.BlackQueen */]: new URL('../../../../../assets/pieces/chessnut/bQ.svg', import.meta.url).toString(),
|
|
10
|
+
[12 /* PieceCode.BlackRook */]: new URL('../../../../../assets/pieces/chessnut/bR.svg', import.meta.url).toString(),
|
|
11
|
+
[11 /* PieceCode.BlackBishop */]: new URL('../../../../../assets/pieces/chessnut/bB.svg', import.meta.url).toString(),
|
|
12
|
+
[10 /* PieceCode.BlackKnight */]: new URL('../../../../../assets/pieces/chessnut/bN.svg', import.meta.url).toString(),
|
|
13
|
+
[9 /* PieceCode.BlackPawn */]: new URL('../../../../../assets/pieces/chessnut/bP.svg', import.meta.url).toString()
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Default board renderer configuration.
|
|
17
|
+
*/
|
|
18
|
+
export const DEFAULT_MAIN_RENDERER_CONFIG = {
|
|
19
|
+
colors: {
|
|
20
|
+
board: {
|
|
21
|
+
light: '#d7dde5',
|
|
22
|
+
dark: '#707a8a'
|
|
23
|
+
},
|
|
24
|
+
coordinates: {
|
|
25
|
+
light: '#eef2f7',
|
|
26
|
+
dark: '#707a8a'
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
pieceUrls: CHESSNUT_PIECE_URLS
|
|
30
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import assert from '@ktarmyshov/assert';
|
|
2
|
+
import { toMerged } from 'es-toolkit';
|
|
3
|
+
import { createSvgElement, updateElementAttributes } from '../../../render/svg/helpers';
|
|
4
|
+
import { isUpdateContextRenderable } from '../../types/context/update';
|
|
5
|
+
import { extensionCreateInternalBase, extensionDestroy, extensionMount, extensionUnmount } from '../common/helpers';
|
|
6
|
+
import { DEFAULT_CONFIG, EXTENSION_ID, EXTENSION_SLOTS } from './types';
|
|
7
|
+
export function createSelectedSquare(config = {}) {
|
|
8
|
+
const mergedConfig = toMerged(DEFAULT_CONFIG, config);
|
|
9
|
+
return {
|
|
10
|
+
id: EXTENSION_ID,
|
|
11
|
+
slots: EXTENSION_SLOTS,
|
|
12
|
+
createInstance() {
|
|
13
|
+
return createSelectedSquareInstance(mergedConfig);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function createSelectedSquareInternal(config) {
|
|
18
|
+
return {
|
|
19
|
+
...extensionCreateInternalBase(),
|
|
20
|
+
svgRect: null,
|
|
21
|
+
config
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function extensionClean(state) {
|
|
25
|
+
state.svgRect = null;
|
|
26
|
+
}
|
|
27
|
+
function createSelectedSquareInstance(config) {
|
|
28
|
+
const internalState = createSelectedSquareInternal(config);
|
|
29
|
+
return {
|
|
30
|
+
id: EXTENSION_ID,
|
|
31
|
+
mount(env) {
|
|
32
|
+
extensionMount(internalState, env.slotRoots);
|
|
33
|
+
},
|
|
34
|
+
onUpdate(context) {
|
|
35
|
+
const needsRender = context.mutation.hasMutation({
|
|
36
|
+
causes: [
|
|
37
|
+
'state.interaction.setSelectedSquare',
|
|
38
|
+
'state.interaction.clear',
|
|
39
|
+
'layout.refreshGeometry'
|
|
40
|
+
]
|
|
41
|
+
}) && isUpdateContextRenderable(context);
|
|
42
|
+
if (!needsRender) {
|
|
43
|
+
return; // no-op
|
|
44
|
+
}
|
|
45
|
+
context.invalidation.markDirty(1 /* DirtyLayer.Highlight */);
|
|
46
|
+
},
|
|
47
|
+
render(context) {
|
|
48
|
+
assert(context.invalidation.dirtyLayers !== 0, 'Render should only be called when there are dirty layers');
|
|
49
|
+
const selectedSquare = context.currentFrame.state.interaction.selected?.square;
|
|
50
|
+
if (selectedSquare === undefined || selectedSquare === null) {
|
|
51
|
+
if (internalState.svgRect !== null) {
|
|
52
|
+
internalState.svgRect.remove();
|
|
53
|
+
internalState.svgRect = null;
|
|
54
|
+
}
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const geometry = context.currentFrame.layout.geometry;
|
|
58
|
+
const r = geometry.squareRect(selectedSquare);
|
|
59
|
+
const rectAttributes = {
|
|
60
|
+
x: r.x.toString(),
|
|
61
|
+
y: r.y.toString(),
|
|
62
|
+
width: r.size.toString(),
|
|
63
|
+
height: r.size.toString(),
|
|
64
|
+
fill: internalState.config.color,
|
|
65
|
+
'fill-opacity': internalState.config.opacity.toString(),
|
|
66
|
+
'shape-rendering': 'crispEdges'
|
|
67
|
+
};
|
|
68
|
+
if (internalState.svgRect === null) {
|
|
69
|
+
assert(internalState.slotRoots, 'Slot roots should be available when render is called');
|
|
70
|
+
internalState.svgRect = createSvgElement(internalState.slotRoots.underPieces, 'rect', {
|
|
71
|
+
'data-chessboard-id': 'selected-square-highlight',
|
|
72
|
+
...rectAttributes
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
updateElementAttributes(internalState.svgRect, rectAttributes);
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
unmount() {
|
|
80
|
+
extensionUnmount(internalState);
|
|
81
|
+
extensionClean(internalState);
|
|
82
|
+
},
|
|
83
|
+
destroy() {
|
|
84
|
+
extensionDestroy(internalState);
|
|
85
|
+
extensionClean(internalState);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
}
|