@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,6 +1,6 @@
|
|
|
1
|
-
import { ExtensionInvalidationState } from '../../invalidation/types';
|
|
2
|
-
import { ExtensionAnimationSession } from '../basic/animation';
|
|
3
|
-
import { ExtensionRenderContext } from './render';
|
|
1
|
+
import { ExtensionInvalidationState } from '../../invalidation/types.js';
|
|
2
|
+
import { ExtensionAnimationSession } from '../basic/animation.js';
|
|
3
|
+
import { ExtensionRenderContext } from './render.js';
|
|
4
4
|
export interface ExtensionSubmittedAnimationSession extends ExtensionAnimationSession {
|
|
5
5
|
readonly status: 'submitted';
|
|
6
6
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ExtensionReadonlyInvalidationState } from '../../invalidation/types';
|
|
2
|
-
import { RenderFrameSnapshot } from '../basic/render';
|
|
1
|
+
import { ExtensionReadonlyInvalidationState } from '../../invalidation/types.js';
|
|
2
|
+
import { RenderFrameSnapshot } from '../basic/render.js';
|
|
3
3
|
export interface ExtensionRenderContext {
|
|
4
4
|
readonly currentFrame: RenderFrameSnapshot;
|
|
5
5
|
readonly invalidation: ExtensionReadonlyInvalidationState;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ReadonlyDeep } from 'type-fest';
|
|
2
|
-
import { RenderFrameSnapshot } from '../basic/render';
|
|
3
|
-
import { TransientInput } from '../basic/transient-visuals';
|
|
2
|
+
import { RenderFrameSnapshot } from '../basic/render.js';
|
|
3
|
+
import { TransientInput } from '../basic/transient-visuals.js';
|
|
4
4
|
export interface ExtensionRenderTransientVisualsContext {
|
|
5
5
|
readonly currentFrame: RenderFrameSnapshot;
|
|
6
6
|
readonly transientInput: ReadonlyDeep<TransientInput>;
|
|
@@ -1,16 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export interface ExtensionUIMoveRequestContextSnapshot {
|
|
5
|
-
readonly status: ExtensionUIMoveRequestStatus;
|
|
6
|
-
readonly sourceSquare: Square;
|
|
7
|
-
readonly destination: MoveDestinationSnapshot;
|
|
8
|
-
readonly canBeAutoResolved: boolean;
|
|
9
|
-
readonly resolvedMoveRequest: MoveRequest | null;
|
|
10
|
-
}
|
|
11
|
-
export interface ExtensionUIMoveRequestContext extends ExtensionUIMoveRequestContextSnapshot {
|
|
12
|
-
defer(): void;
|
|
13
|
-
resolve(request: MoveRequest): void;
|
|
14
|
-
autoresolve(): void;
|
|
15
|
-
getSnapshot(): ExtensionUIMoveRequestContextSnapshot;
|
|
1
|
+
import { PendingUIMoveRequest } from '../../../state/change/types/ui-move.js';
|
|
2
|
+
export interface ExtensionPendingUIMoveRequestContext {
|
|
3
|
+
readonly request: PendingUIMoveRequest;
|
|
16
4
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { RuntimeReadonlyMutationSession } from '../../../runtime/mutation/types';
|
|
2
|
-
import { ExtensionInvalidationState } from '../../invalidation/types';
|
|
3
|
-
import { RenderFrameSnapshot } from '../basic/render';
|
|
4
|
-
import { UpdateFrameSnapshot, UpdateFrameSnapshotMounted, UpdateFrameSnapshotUnmounted } from '../basic/update';
|
|
1
|
+
import { RuntimeReadonlyMutationSession } from '../../../runtime/mutation/types.js';
|
|
2
|
+
import { ExtensionInvalidationState } from '../../invalidation/types.js';
|
|
3
|
+
import { RenderFrameSnapshot } from '../basic/render.js';
|
|
4
|
+
import { UpdateFrameSnapshot, UpdateFrameSnapshotMounted, UpdateFrameSnapshotUnmounted } from '../basic/update.js';
|
|
5
5
|
export interface ExtensionUpdateContextCommon {
|
|
6
6
|
readonly previousFrame: UpdateFrameSnapshot | null;
|
|
7
7
|
readonly mutation: RuntimeReadonlyMutationSession;
|
|
@@ -1,25 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ExtensionInstanceMountOptions, ExtensionSlotName } from './basic/mount';
|
|
3
|
-
import { ExtensionAnimationFinishedContext, ExtensionCleanAnimationContext, ExtensionPrepareAnimationContext, ExtensionRenderAnimationContext } from './context/animation';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
1
|
+
import { ExtensionDragSessionSnapshot } from './basic/interaction.js';
|
|
2
|
+
import { ExtensionInstanceMountOptions, ExtensionSlotName } from './basic/mount.js';
|
|
3
|
+
import { ExtensionAnimationFinishedContext, ExtensionCleanAnimationContext, ExtensionPrepareAnimationContext, ExtensionRenderAnimationContext } from './context/animation.js';
|
|
4
|
+
import { ExtensionOnEventContext } from './context/events.js';
|
|
5
|
+
import { ExtensionRenderContext } from './context/render.js';
|
|
6
|
+
import { ExtensionRenderTransientVisualsContext } from './context/transient-visuals.js';
|
|
7
|
+
import { ExtensionPendingUIMoveRequestContext } from './context/ui-move.js';
|
|
8
|
+
import { ExtensionUpdateContext } from './context/update.js';
|
|
9
|
+
import { ExtensionRuntimeSurface } from './surface/main.js';
|
|
9
10
|
interface ExtensionInstanceBase<TId extends string, TSlots extends readonly ExtensionSlotName[]> {
|
|
10
11
|
readonly id: TId;
|
|
11
|
-
mount(env: ExtensionInstanceMountOptions<TSlots>): void;
|
|
12
|
-
unmount(): void;
|
|
13
|
-
destroy(): void;
|
|
14
|
-
onUpdate(context: ExtensionUpdateContext): void;
|
|
15
|
-
onUIMoveRequest?(context: ExtensionUIMoveRequestContext): void;
|
|
12
|
+
mount?(env: ExtensionInstanceMountOptions<TSlots>): void;
|
|
13
|
+
unmount?(): void;
|
|
14
|
+
destroy?(): void;
|
|
15
|
+
onUpdate?(context: ExtensionUpdateContext): void;
|
|
16
16
|
render?(context: ExtensionRenderContext): void;
|
|
17
17
|
prepareAnimation?(context: ExtensionPrepareAnimationContext): void;
|
|
18
18
|
renderAnimation?(context: ExtensionRenderAnimationContext): void;
|
|
19
19
|
onAnimationFinished?(context: ExtensionAnimationFinishedContext): void;
|
|
20
20
|
cleanAnimation?(context: ExtensionCleanAnimationContext): void;
|
|
21
|
+
completeDrag?(session: ExtensionDragSessionSnapshot): void;
|
|
21
22
|
renderTransientVisuals?(context: ExtensionRenderTransientVisualsContext): void;
|
|
22
|
-
|
|
23
|
+
onUIMoveRequest?(context: ExtensionPendingUIMoveRequestContext): void;
|
|
24
|
+
onEvent?(context: ExtensionOnEventContext): void;
|
|
23
25
|
}
|
|
24
26
|
type ExtensionInstancePublicPart<TPublic> = [TPublic] extends [never] ? Record<never, never> : {
|
|
25
27
|
getPublic(): TPublic;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { RuntimeReadonlyMutationSession } from '../../runtime/mutation/types';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { UpdateFrameSnapshot } from './basic/update';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
1
|
+
import { RuntimeReadonlyMutationSession } from '../../runtime/mutation/types.js';
|
|
2
|
+
import { DragSessionExtensionOwned } from '../../state/interaction/types/internal.js';
|
|
3
|
+
import { ExtensionInvalidationState } from '../invalidation/types.js';
|
|
4
|
+
import { ExtensionAnimationControllerInternalSurface } from './basic/animation.js';
|
|
5
|
+
import { UpdateFrameSnapshot } from './basic/update.js';
|
|
6
|
+
import { ExtensionOnEventContext } from './context/events.js';
|
|
7
|
+
import { ExtensionPendingUIMoveRequestContext } from './context/ui-move.js';
|
|
8
|
+
import { AnyExtensionDefinition, AnyExtensionInstance } from './extension.js';
|
|
9
|
+
import { ExtensionRuntimeSurfaceCommandsInternalSurface } from './surface/commands.js';
|
|
10
|
+
import { ExtensionRuntimeSurfaceEvents } from './surface/events.js';
|
|
9
11
|
export interface ExtensionSystemExtensionRecord {
|
|
10
12
|
readonly id: string;
|
|
11
13
|
readonly definition: AnyExtensionDefinition;
|
|
@@ -14,13 +16,14 @@ export interface ExtensionSystemExtensionRecord {
|
|
|
14
16
|
readonly animation: ExtensionAnimationControllerInternalSurface;
|
|
15
17
|
}
|
|
16
18
|
export interface ExtensionSystemInitOptions {
|
|
17
|
-
extensionRuntimeSurfaceCommands:
|
|
19
|
+
extensionRuntimeSurfaceCommands: ExtensionRuntimeSurfaceCommandsInternalSurface;
|
|
20
|
+
extensionRuntimeSurfaceEvents: ExtensionRuntimeSurfaceEvents;
|
|
18
21
|
extensions?: readonly AnyExtensionDefinition[];
|
|
19
22
|
}
|
|
20
23
|
export interface ExtensionSystemInternal {
|
|
21
24
|
readonly extensions: Map<string, ExtensionSystemExtensionRecord>;
|
|
22
25
|
readonly transientVisualsSubscribers: Set<string>;
|
|
23
|
-
readonly eventSubscribers: Map<string, Set<
|
|
26
|
+
readonly eventSubscribers: Map<string, Set<string>>;
|
|
24
27
|
currentFrame: UpdateFrameSnapshot | null;
|
|
25
28
|
}
|
|
26
29
|
export interface ExtensionSystemUpdateRequest {
|
|
@@ -37,7 +40,9 @@ export interface ExtensionSystem {
|
|
|
37
40
|
getPublicRecord(): Readonly<Record<string, unknown>>;
|
|
38
41
|
getSharedDataForRenderSystem(): ExtensionSystemSharedDataForRenderSystem;
|
|
39
42
|
onUpdate(request: ExtensionSystemUpdateRequest): void;
|
|
40
|
-
onUIMoveRequest(context:
|
|
43
|
+
onUIMoveRequest(context: ExtensionPendingUIMoveRequestContext): void;
|
|
44
|
+
onEvent(context: ExtensionOnEventContext): void;
|
|
45
|
+
completeDrag(session: DragSessionExtensionOwned): void;
|
|
41
46
|
onUnmount(): void;
|
|
42
47
|
onDestroy(): void;
|
|
43
48
|
}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import { LayoutSnapshot } from '../../../layout/types';
|
|
2
|
-
import { ColorInput, MoveRequestInput, PiecePositionInput, PositionInput, SquareString } from '../../../state/board/types/input';
|
|
3
|
-
import { Move } from '../../../state/board/types/internal';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import { LayoutSnapshot } from '../../../layout/types.js';
|
|
2
|
+
import { ColorInput, MoveRequestInput, PiecePositionInput, PositionInput, SquareString } from '../../../state/board/types/input.js';
|
|
3
|
+
import { Move } from '../../../state/board/types/internal.js';
|
|
4
|
+
import { DeferredUIMoveResolutionDetails } from '../../../state/change/types/ui-move.js';
|
|
5
|
+
import { MovabilityInput } from '../../../state/interaction/types/input.js';
|
|
6
|
+
import { DragSessionExtensionOwned } from '../../../state/interaction/types/internal.js';
|
|
7
|
+
import { RuntimeStateSnapshot } from '../../../state/types.js';
|
|
8
|
+
import { ExtensionDragSession } from '../basic/interaction.js';
|
|
6
9
|
export interface ExtensionRuntimeSurfaceCommandsSnapshot {
|
|
7
10
|
readonly state: RuntimeStateSnapshot;
|
|
8
11
|
readonly layout: LayoutSnapshot;
|
|
@@ -19,8 +22,14 @@ export interface ExtensionRuntimeSurfaceCommands {
|
|
|
19
22
|
setOrientation(orientation: ColorInput): boolean;
|
|
20
23
|
setMovability(movability: MovabilityInput): boolean;
|
|
21
24
|
select(square: SquareString | null): boolean;
|
|
25
|
+
startDrag(session: ExtensionDragSession): boolean;
|
|
22
26
|
clearActiveInteraction(): boolean;
|
|
23
27
|
clearInteraction(): boolean;
|
|
28
|
+
resolveDeferredUIMoveRequest(details: DeferredUIMoveResolutionDetails): Move;
|
|
29
|
+
cancelDeferredUIMoveRequest(): boolean;
|
|
24
30
|
requestRender(request: ExtensionRuntimeSurfaceCommandsRenderRequest): void;
|
|
25
31
|
getSnapshot(): ExtensionRuntimeSurfaceCommandsSnapshot;
|
|
26
32
|
}
|
|
33
|
+
export interface ExtensionRuntimeSurfaceCommandsInternalSurface extends ExtensionRuntimeSurfaceCommands {
|
|
34
|
+
startDrag(session: DragSessionExtensionOwned): boolean;
|
|
35
|
+
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { SceneEventType } from '../basic/events';
|
|
2
1
|
export interface ExtensionRuntimeSurfaceEvents {
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
subscribeEvent<K extends keyof HTMLElementEventMap>(type: K): void;
|
|
3
|
+
unsubscribeEvent<K extends keyof HTMLElementEventMap>(type: K): void;
|
|
5
4
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ExtensionAnimationController } from '../basic/animation';
|
|
2
|
-
import { ExtensionRuntimeSurfaceCommands } from './commands';
|
|
3
|
-
import { ExtensionRuntimeSurfaceEvents } from './events';
|
|
4
|
-
import { ExtensionRuntimeSurfaceTransientVisuals } from './transient-visuals';
|
|
1
|
+
import { ExtensionAnimationController } from '../basic/animation.js';
|
|
2
|
+
import { ExtensionRuntimeSurfaceCommands } from './commands.js';
|
|
3
|
+
import { ExtensionRuntimeSurfaceEvents } from './events.js';
|
|
4
|
+
import { ExtensionRuntimeSurfaceTransientVisuals } from './transient-visuals.js';
|
|
5
5
|
export interface ExtensionRuntimeSurface {
|
|
6
6
|
readonly commands: ExtensionRuntimeSurfaceCommands;
|
|
7
7
|
readonly animation: ExtensionAnimationController;
|
|
@@ -1,26 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Public built-in extension ids accepted by createBoard({ extensions })
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
4
|
+
import { createActiveTarget } from '../first-party/active-target/factory.js';
|
|
5
|
+
import { createAutoPromote } from '../first-party/auto-promote/factory.js';
|
|
6
|
+
import { createBoardEvents } from '../first-party/board-events/factory.js';
|
|
7
|
+
import { createLastMove } from '../first-party/last-move/factory.js';
|
|
8
|
+
import { createLegalMoves } from '../first-party/legal-moves/factory.js';
|
|
9
|
+
import { createMainRenderer } from '../first-party/main-renderer/factory.js';
|
|
10
|
+
import { createPromotion } from '../first-party/promotion/factory.js';
|
|
11
|
+
import { createSelectedSquare } from '../first-party/selected-square/factory.js';
|
|
12
|
+
export declare const builtInExtensionFactoryMap: {
|
|
13
|
+
renderer: typeof createMainRenderer;
|
|
14
|
+
selectedSquare: typeof createSelectedSquare;
|
|
15
|
+
lastMove: typeof createLastMove;
|
|
16
|
+
activeTarget: typeof createActiveTarget;
|
|
17
|
+
legalMoves: typeof createLegalMoves;
|
|
18
|
+
events: typeof createBoardEvents;
|
|
19
|
+
autoPromote: typeof createAutoPromote;
|
|
20
|
+
promotion: typeof createPromotion;
|
|
21
|
+
};
|
|
22
|
+
export type BuiltInExtensionId = keyof typeof builtInExtensionFactoryMap;
|
|
23
|
+
export type BuiltInExtensionDefinitionMap = {
|
|
24
|
+
[Id in BuiltInExtensionId]: ReturnType<(typeof builtInExtensionFactoryMap)[Id]>;
|
|
25
|
+
};
|
|
26
|
+
export declare const DefaultBuiltinChessboardExtensions: readonly ["renderer", "selectedSquare", "lastMove", "activeTarget", "legalMoves", "events", "autoPromote", "promotion"];
|
|
15
27
|
export type DefaultBuiltinChessboardExtensions = typeof DefaultBuiltinChessboardExtensions;
|
|
16
|
-
/**
|
|
17
|
-
* Map built-in public ids -> concrete extension definition types
|
|
18
|
-
*/
|
|
19
|
-
export interface BuiltInExtensionDefinitionMap {
|
|
20
|
-
mainRenderer: MainRendererDefinition;
|
|
21
|
-
events: BoardEventsDefinition;
|
|
22
|
-
selectedSquare: SelectedSquareDefinition;
|
|
23
|
-
activeTarget: ActiveTargetDefinition;
|
|
24
|
-
legalMoves: LegalMovesDefinition;
|
|
25
|
-
lastMove: LastMoveDefinition;
|
|
26
|
-
}
|
|
@@ -1,11 +1,39 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Public built-in extension ids accepted by createBoard({ extensions })
|
|
3
3
|
*/
|
|
4
|
+
import { createActiveTarget } from '../first-party/active-target/factory.js';
|
|
5
|
+
import { EXTENSION_ID as EXTENSION_ID_ACTIVE_TARGET } from '../first-party/active-target/types.js';
|
|
6
|
+
import { createAutoPromote } from '../first-party/auto-promote/factory.js';
|
|
7
|
+
import { EXTENSION_ID as EXTENSION_ID_AUTO_PROMOTE } from '../first-party/auto-promote/types.js';
|
|
8
|
+
import { createBoardEvents } from '../first-party/board-events/factory.js';
|
|
9
|
+
import { EXTENSION_ID as EXTENSION_ID_BOARD_EVENTS } from '../first-party/board-events/types.js';
|
|
10
|
+
import { createLastMove } from '../first-party/last-move/factory.js';
|
|
11
|
+
import { EXTENSION_ID as EXTENSION_ID_LAST_MOVE } from '../first-party/last-move/types.js';
|
|
12
|
+
import { createLegalMoves } from '../first-party/legal-moves/factory.js';
|
|
13
|
+
import { EXTENSION_ID as EXTENSION_ID_LEGAL_MOVES } from '../first-party/legal-moves/types.js';
|
|
14
|
+
import { createMainRenderer } from '../first-party/main-renderer/factory.js';
|
|
15
|
+
import { EXTENSION_ID as EXTENSION_ID_RENDERER } from '../first-party/main-renderer/types/extension.js';
|
|
16
|
+
import { createPromotion } from '../first-party/promotion/factory.js';
|
|
17
|
+
import { EXTENSION_ID as EXTENSION_ID_PROMOTION } from '../first-party/promotion/types/main.js';
|
|
18
|
+
import { createSelectedSquare } from '../first-party/selected-square/factory.js';
|
|
19
|
+
import { EXTENSION_ID as EXTENSION_ID_SELECTED_SQUARE } from '../first-party/selected-square/types.js';
|
|
20
|
+
export const builtInExtensionFactoryMap = {
|
|
21
|
+
[EXTENSION_ID_RENDERER]: createMainRenderer,
|
|
22
|
+
[EXTENSION_ID_SELECTED_SQUARE]: createSelectedSquare,
|
|
23
|
+
[EXTENSION_ID_LAST_MOVE]: createLastMove,
|
|
24
|
+
[EXTENSION_ID_ACTIVE_TARGET]: createActiveTarget,
|
|
25
|
+
[EXTENSION_ID_LEGAL_MOVES]: createLegalMoves,
|
|
26
|
+
[EXTENSION_ID_BOARD_EVENTS]: createBoardEvents,
|
|
27
|
+
[EXTENSION_ID_AUTO_PROMOTE]: createAutoPromote,
|
|
28
|
+
[EXTENSION_ID_PROMOTION]: createPromotion
|
|
29
|
+
};
|
|
4
30
|
export const DefaultBuiltinChessboardExtensions = [
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
31
|
+
EXTENSION_ID_RENDERER,
|
|
32
|
+
EXTENSION_ID_SELECTED_SQUARE,
|
|
33
|
+
EXTENSION_ID_LAST_MOVE,
|
|
34
|
+
EXTENSION_ID_ACTIVE_TARGET,
|
|
35
|
+
EXTENSION_ID_LEGAL_MOVES,
|
|
36
|
+
EXTENSION_ID_BOARD_EVENTS,
|
|
37
|
+
EXTENSION_ID_AUTO_PROMOTE,
|
|
38
|
+
EXTENSION_ID_PROMOTION
|
|
11
39
|
];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ExtensionSystemInternal, ExtensionSystemUpdateRequest } from './types/main';
|
|
1
|
+
import { ExtensionPendingUIMoveRequestContext } from './types/context/ui-move.js';
|
|
2
|
+
import { ExtensionSystemInternal, ExtensionSystemUpdateRequest } from './types/main.js';
|
|
3
3
|
export declare function extensionSystemUpdateState(state: ExtensionSystemInternal, request: ExtensionSystemUpdateRequest): void;
|
|
4
|
-
export declare function extensionSystemUpdateUIMoveRequest(state: ExtensionSystemInternal, context:
|
|
4
|
+
export declare function extensionSystemUpdateUIMoveRequest(state: ExtensionSystemInternal, context: ExtensionPendingUIMoveRequestContext): void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isUpdateContextCommonMounted } from './types/context/update';
|
|
1
|
+
import { isUpdateContextCommonMounted } from './types/context/update.js';
|
|
2
2
|
export function extensionSystemUpdateState(state, request) {
|
|
3
3
|
// Prepare base context
|
|
4
4
|
const contextCommon = {
|
|
@@ -16,7 +16,7 @@ export function extensionSystemUpdateState(state, request) {
|
|
|
16
16
|
: {
|
|
17
17
|
...contextCommon
|
|
18
18
|
};
|
|
19
|
-
extension.instance.onUpdate(context);
|
|
19
|
+
extension.instance.onUpdate?.(context);
|
|
20
20
|
}
|
|
21
21
|
state.currentFrame = request.state;
|
|
22
22
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { createBoard } from './wrapper/factory';
|
|
2
|
-
export type { Chessboard, ChessboardExtensionInput, ChessboardInitOptions, ChessboardRuntimeSurface } from './wrapper/types';
|
|
3
|
-
export type { MoveRequestInput, PiecePositionRecordString } from './state/board/types/input';
|
|
4
|
-
export type { RuntimeStateInitOptions } from './state/types';
|
|
1
|
+
export { createBoard } from './wrapper/factory.js';
|
|
2
|
+
export type { Chessboard, ChessboardExtensionInput, ChessboardInitOptions, ChessboardRuntimeSurface } from './wrapper/types.js';
|
|
3
|
+
export type { MoveRequestInput, PiecePositionRecordString } from './state/board/types/input.js';
|
|
4
|
+
export type { RuntimeStateInitOptions } from './state/types.js';
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { createBoard } from './wrapper/factory';
|
|
1
|
+
export { createBoard } from './wrapper/factory.js';
|
package/dist/layout/factory.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Layout } from './types';
|
|
1
|
+
import { Layout } from './types.js';
|
|
2
2
|
export declare function createLayout(): Layout;
|
package/dist/layout/factory.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { cloneDeep } from 'es-toolkit/object';
|
|
2
|
-
import { layoutRefreshGeometry } from './reducers';
|
|
2
|
+
import { layoutRefreshGeometry } from './reducers.js';
|
|
3
3
|
function createLayoutInternal() {
|
|
4
4
|
return {
|
|
5
|
-
|
|
5
|
+
sceneSize: null,
|
|
6
6
|
orientation: 0 /* ColorCode.White */,
|
|
7
7
|
geometry: null,
|
|
8
8
|
layoutEpoch: 0
|
|
@@ -11,8 +11,8 @@ function createLayoutInternal() {
|
|
|
11
11
|
export function createLayout() {
|
|
12
12
|
const internalState = createLayoutInternal();
|
|
13
13
|
return {
|
|
14
|
-
get
|
|
15
|
-
return internalState.
|
|
14
|
+
get sceneSize() {
|
|
15
|
+
return internalState.sceneSize;
|
|
16
16
|
},
|
|
17
17
|
get orientation() {
|
|
18
18
|
return internalState.orientation;
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
import { ColorCode } from '../../state/board/types/internal';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
* Create RenderGeometry for a given board size (in px) and orientation.
|
|
5
|
-
* - Geometry uses an SVG-local coordinate system with origin at top-left.
|
|
6
|
-
* - Orientation mapping:
|
|
7
|
-
* - 'white': files increase left→right (a..h), ranks increase bottom→top (1..8).
|
|
8
|
-
* yIndex = 7 - rank, xIndex = file
|
|
9
|
-
* - 'black': files increase right→left (a..h), ranks increase top→bottom (1..8).
|
|
10
|
-
* yIndex = rank, xIndex = 7 - file
|
|
11
|
-
*/
|
|
12
|
-
export declare function createRenderGeometry(boardSize: number, orientation: ColorCode): RenderGeometry;
|
|
1
|
+
import { ColorCode } from '../../state/board/types/internal.js';
|
|
2
|
+
import { SceneRenderGeometry, Size } from './types.js';
|
|
3
|
+
export declare function createRenderGeometry(sceneSize: Size, orientation: ColorCode): SceneRenderGeometry;
|
|
@@ -1,32 +1,31 @@
|
|
|
1
|
-
import { fileOf, rankOf } from '../../state/board/coords';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
* yIndex = rank, xIndex = 7 - file
|
|
10
|
-
*/
|
|
11
|
-
export function createRenderGeometry(boardSize, orientation) {
|
|
12
|
-
if (!(boardSize > 0 && Number.isFinite(boardSize))) {
|
|
13
|
-
throw new RangeError(`Invalid boardSize: ${boardSize}`);
|
|
1
|
+
import { fileOf, rankOf } from '../../state/board/coords.js';
|
|
2
|
+
import { makeBoardRect, measureBoardSize } from './helpers.js';
|
|
3
|
+
export function createRenderGeometry(sceneSize, orientation) {
|
|
4
|
+
if (!(sceneSize.height > 0 &&
|
|
5
|
+
Number.isFinite(sceneSize.height) &&
|
|
6
|
+
sceneSize.width > 0 &&
|
|
7
|
+
Number.isFinite(sceneSize.width))) {
|
|
8
|
+
throw new RangeError(`Invalid sceneSize: ${JSON.stringify(sceneSize)}`);
|
|
14
9
|
}
|
|
10
|
+
const boardSize = measureBoardSize(sceneSize);
|
|
11
|
+
const boardRect = makeBoardRect(sceneSize);
|
|
15
12
|
const squareSize = boardSize / 8;
|
|
16
13
|
const white = orientation === 0 /* ColorCode.White */;
|
|
17
14
|
return {
|
|
18
|
-
|
|
15
|
+
sceneSize: { ...sceneSize },
|
|
16
|
+
boardRect,
|
|
19
17
|
squareSize,
|
|
20
18
|
orientation,
|
|
21
|
-
|
|
19
|
+
getSquareRect(sq) {
|
|
22
20
|
const f = fileOf(sq);
|
|
23
21
|
const r = rankOf(sq);
|
|
24
22
|
const xIndex = white ? f : 7 - f;
|
|
25
23
|
const yIndex = white ? 7 - r : r;
|
|
26
24
|
return {
|
|
27
|
-
x: xIndex * squareSize,
|
|
28
|
-
y: yIndex * squareSize,
|
|
29
|
-
|
|
25
|
+
x: boardRect.x + xIndex * squareSize,
|
|
26
|
+
y: boardRect.y + yIndex * squareSize,
|
|
27
|
+
width: squareSize,
|
|
28
|
+
height: squareSize
|
|
30
29
|
};
|
|
31
30
|
}
|
|
32
31
|
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Rect, RectSnapshot, Size, SizeSnapshot } from './types.js';
|
|
2
|
+
export declare function sceneRectsEqual(rect1: RectSnapshot | null, rect2: RectSnapshot | null): boolean;
|
|
3
|
+
export declare function sceneSizesEqual(size1: SizeSnapshot | null, size2: SizeSnapshot | null): boolean;
|
|
4
|
+
export declare function measureBoardSize(sceneSize: Size): number;
|
|
5
|
+
export declare function makeBoardRect(sceneSize: Size): Rect;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export function sceneRectsEqual(rect1, rect2) {
|
|
2
|
+
if (rect1 === null && rect2 === null) {
|
|
3
|
+
return true;
|
|
4
|
+
}
|
|
5
|
+
if (rect1 === null || rect2 === null) {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
return (rect1.x === rect2.x &&
|
|
9
|
+
rect1.y === rect2.y &&
|
|
10
|
+
rect1.width === rect2.width &&
|
|
11
|
+
rect1.height === rect2.height);
|
|
12
|
+
}
|
|
13
|
+
export function sceneSizesEqual(size1, size2) {
|
|
14
|
+
if (size1 === null && size2 === null) {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
if (size1 === null || size2 === null) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
return size1.width === size2.width && size1.height === size2.height;
|
|
21
|
+
}
|
|
22
|
+
export function measureBoardSize(sceneSize) {
|
|
23
|
+
return Math.min(sceneSize.width, sceneSize.height);
|
|
24
|
+
}
|
|
25
|
+
export function makeBoardRect(sceneSize) {
|
|
26
|
+
const boardSize = measureBoardSize(sceneSize);
|
|
27
|
+
return {
|
|
28
|
+
x: (sceneSize.width - boardSize) / 2,
|
|
29
|
+
y: (sceneSize.height - boardSize) / 2,
|
|
30
|
+
width: boardSize,
|
|
31
|
+
height: boardSize
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import { ReadonlyDeep } from 'type-fest';
|
|
2
|
-
import { ColorCode, Square } from '../../state/board/types/internal';
|
|
3
|
-
export interface
|
|
2
|
+
import { ColorCode, Square } from '../../state/board/types/internal.js';
|
|
3
|
+
export interface Size {
|
|
4
|
+
width: number;
|
|
5
|
+
height: number;
|
|
6
|
+
}
|
|
7
|
+
export type SizeSnapshot = ReadonlyDeep<Size>;
|
|
8
|
+
export interface Rect {
|
|
4
9
|
x: number;
|
|
5
10
|
y: number;
|
|
6
|
-
|
|
11
|
+
width: number;
|
|
12
|
+
height: number;
|
|
7
13
|
}
|
|
8
|
-
export type
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
*
|
|
13
|
-
* It is computed from layout inputs and used by rendering and interaction code.
|
|
14
|
-
*/
|
|
15
|
-
export interface RenderGeometry {
|
|
16
|
-
readonly boardSize: number;
|
|
14
|
+
export type RectSnapshot = ReadonlyDeep<Rect>;
|
|
15
|
+
export interface SceneRenderGeometry {
|
|
16
|
+
readonly sceneSize: SizeSnapshot;
|
|
17
|
+
readonly boardRect: RectSnapshot;
|
|
17
18
|
readonly squareSize: number;
|
|
18
19
|
readonly orientation: ColorCode;
|
|
19
|
-
|
|
20
|
+
getSquareRect(sq: Square): RectSnapshot;
|
|
20
21
|
}
|
package/dist/layout/helpers.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export declare function measureBoardSize(container: HTMLElement): number;
|
|
1
|
+
import { Size } from './geometry/types.js';
|
|
2
|
+
export declare function measureSceneSize(container: HTMLElement): Size;
|
|
3
|
+
export declare function isSceneSizeValid(size: Size | null): boolean;
|
package/dist/layout/helpers.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export function
|
|
5
|
-
return
|
|
1
|
+
export function measureSceneSize(container) {
|
|
2
|
+
return { width: container.clientWidth, height: container.clientHeight };
|
|
3
|
+
}
|
|
4
|
+
export function isSceneSizeValid(size) {
|
|
5
|
+
return size !== null && size.width > 0 && size.height > 0;
|
|
6
6
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { LayoutInternal, LayoutRefreshOptions } from './types';
|
|
1
|
+
import { LayoutInternal, LayoutRefreshOptions } from './types.js';
|
|
2
2
|
export declare function layoutRefreshGeometry(state: LayoutInternal, options: LayoutRefreshOptions): boolean;
|
package/dist/layout/reducers.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { createRenderGeometry } from './geometry/factory';
|
|
2
|
-
import {
|
|
1
|
+
import { createRenderGeometry } from './geometry/factory.js';
|
|
2
|
+
import { sceneSizesEqual } from './geometry/helpers.js';
|
|
3
|
+
import { isSceneSizeValid, measureSceneSize } from './helpers.js';
|
|
3
4
|
export function layoutRefreshGeometry(state, options) {
|
|
4
5
|
const orientation = options.orientation ?? state.orientation;
|
|
5
6
|
if (orientation === null) {
|
|
@@ -7,23 +8,23 @@ export function layoutRefreshGeometry(state, options) {
|
|
|
7
8
|
// For now we throw
|
|
8
9
|
throw new Error('Orientation is expected to be provided on the first pass of layout.refreshGeometry');
|
|
9
10
|
}
|
|
10
|
-
let
|
|
11
|
-
if (
|
|
12
|
-
|
|
13
|
-
const changed =
|
|
11
|
+
let sceneSize = options.container ? measureSceneSize(options.container) : state.sceneSize;
|
|
12
|
+
if (sceneSize !== null && !isSceneSizeValid(sceneSize))
|
|
13
|
+
sceneSize = null;
|
|
14
|
+
const changed = !sceneSizesEqual(sceneSize, state.sceneSize) || orientation !== state.orientation;
|
|
14
15
|
if (!changed) {
|
|
15
16
|
return false; // no-op, no relevant changes
|
|
16
17
|
}
|
|
17
18
|
// Update the state
|
|
18
|
-
state.
|
|
19
|
+
state.sceneSize = sceneSize;
|
|
19
20
|
state.orientation = orientation;
|
|
20
|
-
if (
|
|
21
|
+
if (sceneSize === null || orientation === null) {
|
|
21
22
|
// General invalid-geometry rule. Orientation is currently guarded above,
|
|
22
23
|
// but this branch stays explicit in case null orientation is allowed later.
|
|
23
24
|
state.geometry = null;
|
|
24
25
|
}
|
|
25
26
|
else {
|
|
26
|
-
state.geometry = createRenderGeometry(
|
|
27
|
+
state.geometry = createRenderGeometry(sceneSize, orientation);
|
|
27
28
|
}
|
|
28
29
|
state.layoutEpoch++;
|
|
29
30
|
return true;
|