@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
package/dist/layout/types.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { ReadonlyDeep } from 'type-fest';
|
|
2
|
-
import { ColorCode } from '../state/board/types/internal';
|
|
3
|
-
import {
|
|
4
|
-
import { LayoutMutationSession } from './mutation';
|
|
2
|
+
import { ColorCode } from '../state/board/types/internal.js';
|
|
3
|
+
import { SceneRenderGeometry, Size } from './geometry/types.js';
|
|
4
|
+
import { LayoutMutationSession } from './mutation.js';
|
|
5
5
|
export interface LayoutInternal {
|
|
6
|
-
|
|
6
|
+
sceneSize: Size | null;
|
|
7
7
|
orientation: ColorCode | null;
|
|
8
|
-
geometry:
|
|
8
|
+
geometry: SceneRenderGeometry | null;
|
|
9
9
|
layoutEpoch: number;
|
|
10
10
|
}
|
|
11
11
|
export type LayoutSnapshot = ReadonlyDeep<LayoutInternal>;
|
|
@@ -14,9 +14,9 @@ export interface LayoutRefreshOptions {
|
|
|
14
14
|
orientation?: ColorCode;
|
|
15
15
|
}
|
|
16
16
|
export interface Layout {
|
|
17
|
-
readonly
|
|
17
|
+
readonly sceneSize: Size | null;
|
|
18
18
|
readonly orientation: ColorCode | null;
|
|
19
|
-
readonly geometry:
|
|
19
|
+
readonly geometry: SceneRenderGeometry | null;
|
|
20
20
|
readonly layoutEpoch: number;
|
|
21
21
|
refreshGeometry(options: LayoutRefreshOptions, mutationSession: LayoutMutationSession): boolean;
|
|
22
22
|
getSnapshot(): LayoutSnapshot;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { MutationPipe, MutationPipeline } from './types';
|
|
1
|
+
import type { MutationPipe, MutationPipeline } from './types.js';
|
|
2
2
|
export declare function createMutationPipeline<PayloadByCause extends Record<string, unknown>, Context>(pipes: readonly MutationPipe<PayloadByCause, Context>[]): MutationPipeline<PayloadByCause, Context>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { MutationCause, MutationSession, ReadonlyMutationSession } from './types';
|
|
1
|
+
import type { MutationCause, MutationSession, ReadonlyMutationSession } from './types.js';
|
|
2
2
|
export declare function createReadonlyMutationSession<PayloadByCause extends Record<string, unknown>>(payloads: ReadonlyMap<MutationCause<PayloadByCause>, PayloadByCause[MutationCause<PayloadByCause>][] | undefined>, clone?: boolean): ReadonlyMutationSession<PayloadByCause>;
|
|
3
3
|
export declare function createMutationSession<PayloadByCause extends Record<string, unknown>>(): MutationSession<PayloadByCause>;
|
package/dist/render/factory.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { RenderSystem, RenderSystemInitOptions } from './types';
|
|
1
|
+
import { RenderSystem, RenderSystemInitOptions } from './types.js';
|
|
2
2
|
export declare function createRenderSystem(options: RenderSystemInitOptions): RenderSystem;
|
package/dist/render/factory.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { renderMount, renderUnmount } from './mount';
|
|
2
|
-
import { performAnimationCleanup, performAnimationPass } from './rendering/animation';
|
|
3
|
-
import { validateIsMounted } from './rendering/helpers';
|
|
4
|
-
import { performRenderPass } from './rendering/state';
|
|
5
|
-
import { performRenderTransientVisualsPass } from './rendering/visuals';
|
|
6
|
-
import { createScheduler } from './scheduler/scheduler';
|
|
7
|
-
import { allocateExtensionSlotRoots, createSvgRoots } from './svg/factory';
|
|
1
|
+
import { renderMount, renderUnmount } from './mount.js';
|
|
2
|
+
import { performAnimationCleanup, performAnimationPass } from './rendering/animation.js';
|
|
3
|
+
import { validateIsMounted } from './rendering/helpers.js';
|
|
4
|
+
import { performRenderPass } from './rendering/state.js';
|
|
5
|
+
import { performRenderTransientVisualsPass } from './rendering/visuals.js';
|
|
6
|
+
import { createScheduler } from './scheduler/scheduler.js';
|
|
7
|
+
import { allocateExtensionSlotRoots, createSvgRoots } from './svg/factory.js';
|
|
8
8
|
function createRenderInternal(options) {
|
|
9
9
|
const svgRoots = createSvgRoots(options);
|
|
10
10
|
const scheduler = createScheduler({
|
package/dist/render/mount.d.ts
CHANGED
package/dist/render/mount.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { validateIsMounted, validateIsNotMounted } from './rendering/helpers';
|
|
2
|
-
import { clearElementChildren } from './svg/helpers';
|
|
1
|
+
import { validateIsMounted, validateIsNotMounted } from './rendering/helpers.js';
|
|
2
|
+
import { clearElementChildren } from './svg/helpers.js';
|
|
3
3
|
export function renderMount(state, element) {
|
|
4
4
|
validateIsNotMounted(state);
|
|
5
5
|
state.container = element;
|
|
@@ -8,13 +8,13 @@ export function renderMount(state, element) {
|
|
|
8
8
|
// Now call onMount for all extensions with their slot roots
|
|
9
9
|
for (const extensionRec of state.extensions.values()) {
|
|
10
10
|
const slotRoots = extensionRec.render.slots;
|
|
11
|
-
extensionRec.extension.instance.mount({ slotRoots });
|
|
11
|
+
extensionRec.extension.instance.mount?.({ slotRoots });
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
export function renderUnmount(state) {
|
|
15
15
|
validateIsMounted(state);
|
|
16
16
|
for (const extensionRec of state.extensions.values()) {
|
|
17
|
-
extensionRec.extension.instance.unmount();
|
|
17
|
+
extensionRec.extension.instance.unmount?.();
|
|
18
18
|
// clear the slot roots
|
|
19
19
|
for (const slotRoot of Object.values(extensionRec.render.slots)) {
|
|
20
20
|
clearElementChildren(slotRoot);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { validateIsMounted } from './helpers';
|
|
1
|
+
import { validateIsMounted } from './helpers.js';
|
|
2
2
|
/**
|
|
3
3
|
* Runs deferred physical cleanup for all sessions that were marked pendingCleanup
|
|
4
4
|
* in a previous animation pass. Called at the end of performRenderPass (after stable
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RenderFrameSnapshot } from '../../extensions/types/basic/render';
|
|
2
|
-
import { RenderSystemInternal } from '../types';
|
|
1
|
+
import { RenderFrameSnapshot } from '../../extensions/types/basic/render.js';
|
|
2
|
+
import { RenderSystemInternal } from '../types.js';
|
|
3
3
|
export declare function checkNeedsRender(state: RenderSystemInternal): boolean;
|
|
4
4
|
export declare function performRenderPass(state: RenderSystemInternal, request: RenderFrameSnapshot | null): void;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { sceneSizesEqual } from '../../layout/geometry/helpers.js';
|
|
2
|
+
import { updateElementAttributes } from '../svg/helpers.js';
|
|
3
|
+
import { validateIsMounted } from './helpers.js';
|
|
3
4
|
export function checkNeedsRender(state) {
|
|
4
5
|
for (const extensionRec of state.extensions.values()) {
|
|
5
6
|
if (extensionRec.extension.invalidation.dirtyLayers !== 0) {
|
|
@@ -16,14 +17,13 @@ export function performRenderPass(state, request) {
|
|
|
16
17
|
if (!request.layout.geometry) {
|
|
17
18
|
throw new Error('render() called without a valid layout geometry');
|
|
18
19
|
}
|
|
19
|
-
const currentSize = request.layout.geometry.
|
|
20
|
-
const prevSize = state.currentFrame?.layout.geometry?.
|
|
21
|
-
if (currentSize
|
|
22
|
-
const size = String(currentSize);
|
|
20
|
+
const currentSize = request.layout.geometry.sceneSize;
|
|
21
|
+
const prevSize = state.currentFrame?.layout.geometry?.sceneSize ?? null;
|
|
22
|
+
if (!sceneSizesEqual(currentSize, prevSize)) {
|
|
23
23
|
updateElementAttributes(state.svgRoots.svgRoot, {
|
|
24
|
-
width:
|
|
25
|
-
height:
|
|
26
|
-
viewBox: `0 0 ${
|
|
24
|
+
width: currentSize.width.toString(),
|
|
25
|
+
height: currentSize.height.toString(),
|
|
26
|
+
viewBox: `0 0 ${currentSize.width} ${currentSize.height}`
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
29
|
// Check if we have any invalidation states
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { TransientInput } from '../../extensions/types/basic/transient-visuals';
|
|
2
|
-
import { RenderSystemInternal } from '../types';
|
|
1
|
+
import { TransientInput } from '../../extensions/types/basic/transient-visuals.js';
|
|
2
|
+
import { RenderSystemInternal } from '../types.js';
|
|
3
3
|
export declare function performRenderTransientVisualsPass(state: RenderSystemInternal, request: TransientInput): void;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Scheduler, SchedulerOptions } from './types';
|
|
1
|
+
import { Scheduler, SchedulerOptions } from './types.js';
|
|
2
2
|
export declare function createScheduler(opts: SchedulerOptions): Scheduler;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ExtensionAllocatedSlotsInternal, ExtensionSlotName } from '../../extensions/types/basic/mount';
|
|
2
|
-
import { RenderSystemInitOptionsInternal, SvgRoots } from '../types';
|
|
1
|
+
import { ExtensionAllocatedSlotsInternal, ExtensionSlotName } from '../../extensions/types/basic/mount.js';
|
|
2
|
+
import { RenderSystemInitOptionsInternal, SvgRoots } from '../types.js';
|
|
3
3
|
export declare function createSvgRoots(options: RenderSystemInitOptionsInternal): SvgRoots;
|
|
4
4
|
export declare function allocateExtensionSlotRoots(svgRoots: SvgRoots, extensionId: string, slots: readonly ExtensionSlotName[]): ExtensionAllocatedSlotsInternal;
|
package/dist/render/types.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { ALL_EXTENSION_SLOTS, ExtensionAllocatedSlotsInternal, ExtensionSlotSvgRoots } from '../extensions/types/basic/mount';
|
|
2
|
-
import { RenderFrameSnapshot } from '../extensions/types/basic/render';
|
|
3
|
-
import { TransientInput } from '../extensions/types/basic/transient-visuals';
|
|
4
|
-
import { ExtensionSystemExtensionRecord, ExtensionSystemSharedDataForRenderSystem } from '../extensions/types/main';
|
|
5
|
-
import { Scheduler } from './scheduler/types';
|
|
1
|
+
import { ALL_EXTENSION_SLOTS, ExtensionAllocatedSlotsInternal, ExtensionSlotSvgRoots } from '../extensions/types/basic/mount.js';
|
|
2
|
+
import { RenderFrameSnapshot } from '../extensions/types/basic/render.js';
|
|
3
|
+
import { TransientInput } from '../extensions/types/basic/transient-visuals.js';
|
|
4
|
+
import { ExtensionSystemExtensionRecord, ExtensionSystemSharedDataForRenderSystem } from '../extensions/types/main.js';
|
|
5
|
+
import { Scheduler } from './scheduler/types.js';
|
|
6
6
|
export interface SvgRoots extends ExtensionSlotSvgRoots<typeof ALL_EXTENSION_SLOTS> {
|
|
7
7
|
readonly svgRoot: SVGSVGElement;
|
|
8
8
|
readonly defs: SVGDefsElement;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import assert from '@ktarmyshov/assert';
|
|
2
|
+
import { NEED_EVENT_TYPES } from '../input/adapter/types.js';
|
|
3
|
+
export function createExtensionRuntimeSurfaceEvents(getInternalState) {
|
|
4
|
+
return {
|
|
5
|
+
subscribeEvent(type) {
|
|
6
|
+
const internalState = getInternalState();
|
|
7
|
+
assert(internalState.inputAdapter, 'Input adapter not available in the current runtime state');
|
|
8
|
+
internalState.inputAdapter.subscribeEvent(type);
|
|
9
|
+
},
|
|
10
|
+
unsubscribeEvent(type) {
|
|
11
|
+
const internalState = getInternalState();
|
|
12
|
+
assert(internalState.inputAdapter, 'Input adapter not available in the current runtime state');
|
|
13
|
+
if (!NEED_EVENT_TYPES.has(type)) {
|
|
14
|
+
internalState.inputAdapter.unsubscribeEvent(type);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Square } from '../../state/board/types/internal';
|
|
2
|
-
import { RuntimeInternal } from '../types/main';
|
|
1
|
+
import { Square } from '../../state/board/types/internal.js';
|
|
2
|
+
import { RuntimeInternal } from '../types/main.js';
|
|
3
3
|
/**
|
|
4
4
|
* Helper functions for common flow for dropTo and releaseTo interactions
|
|
5
5
|
*/
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import assert from '@ktarmyshov/assert';
|
|
2
|
-
import { isEmptyPieceCode } from '../../state/board/check';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
function assertResolvedAfterAutoResolve(
|
|
6
|
-
if (
|
|
2
|
+
import { isEmptyPieceCode } from '../../state/board/check.js';
|
|
3
|
+
import { createPendingUIMoveRequest } from '../../state/change/factory/ui-move.js';
|
|
4
|
+
import { canMoveTo } from '../input/controller/helpers.js';
|
|
5
|
+
function assertResolvedAfterAutoResolve(request) {
|
|
6
|
+
if (request.status !== 'resolved') {
|
|
7
7
|
throw new Error('UI move request must be resolved after autoresolve');
|
|
8
8
|
}
|
|
9
9
|
}
|
|
@@ -22,18 +22,18 @@ export function uiMoveCompleteTo(state, target) {
|
|
|
22
22
|
assert(canMoveTo(interaction.getSnapshot(), target), 'dropTo/releaseTo target must be a valid move destination');
|
|
23
23
|
// canMoveTo already confirmed we can move, but if 'FREE' movability it can be that there are no activeDestinations for the target square, so we need to handle that case as well
|
|
24
24
|
const destination = interaction.activeDestinations.get(target) ?? { to: target };
|
|
25
|
-
const
|
|
26
|
-
state.extensionSystem.onUIMoveRequest(
|
|
27
|
-
if (
|
|
28
|
-
state.state.change.
|
|
25
|
+
const pendingUIMoveRequest = createPendingUIMoveRequest(dragSession.sourceSquare, destination);
|
|
26
|
+
state.extensionSystem.onUIMoveRequest({ request: pendingUIMoveRequest });
|
|
27
|
+
if (pendingUIMoveRequest.status === 'deferred') {
|
|
28
|
+
state.state.change.setDeferredUIMoveRequest(pendingUIMoveRequest, mutationSession);
|
|
29
29
|
}
|
|
30
|
-
else if (
|
|
30
|
+
else if (pendingUIMoveRequest.status === 'unresolved') {
|
|
31
31
|
// Try to auto-resolve if possible (e.g. if there are no promotion choices to be made)
|
|
32
|
-
|
|
33
|
-
assertResolvedAfterAutoResolve(
|
|
32
|
+
pendingUIMoveRequest.autoresolve();
|
|
33
|
+
assertResolvedAfterAutoResolve(pendingUIMoveRequest);
|
|
34
34
|
}
|
|
35
|
-
if (
|
|
36
|
-
const moveRequest =
|
|
35
|
+
if (pendingUIMoveRequest.status === 'resolved') {
|
|
36
|
+
const moveRequest = pendingUIMoveRequest.resolvedMoveRequest;
|
|
37
37
|
if (moveRequest !== null) {
|
|
38
38
|
state.state.board.move(moveRequest, mutationSession);
|
|
39
39
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { RuntimeInteractionSurface } from '../input/controller/types';
|
|
2
|
-
import { GetInternalState } from '../types/main';
|
|
1
|
+
import { RuntimeInteractionSurface } from '../input/controller/types.js';
|
|
2
|
+
import { GetInternalState } from '../types/main.js';
|
|
3
3
|
export declare function createRuntimeInteractionSurface(state: GetInternalState): RuntimeInteractionSurface;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import assert from '@ktarmyshov/assert';
|
|
2
|
-
import { isEmptyPieceCode } from '../../state/board/check';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { isEmptyPieceCode } from '../../state/board/check.js';
|
|
3
|
+
import { isDragSessionCoreOwned } from '../../state/interaction/helpers.js';
|
|
4
|
+
import { runtimeRunMutationPipeline } from '../mutation/run.js';
|
|
5
|
+
import { uiMoveCompleteTo } from './helpers.js';
|
|
5
6
|
export function createRuntimeInteractionSurface(state) {
|
|
6
7
|
return {
|
|
7
8
|
getInteractionStateSnapshot() {
|
|
@@ -24,6 +25,7 @@ export function createRuntimeInteractionSurface(state) {
|
|
|
24
25
|
};
|
|
25
26
|
interaction.setSelected(interactionSource, interactionMutationSession);
|
|
26
27
|
const dragSession = {
|
|
28
|
+
owner: 'core',
|
|
27
29
|
type: 'lifted-piece-drag',
|
|
28
30
|
sourceSquare: interactionSource.square,
|
|
29
31
|
sourcePieceCode: interactionSource.pieceCode,
|
|
@@ -36,27 +38,27 @@ export function createRuntimeInteractionSurface(state) {
|
|
|
36
38
|
const internalState = state();
|
|
37
39
|
internalState.renderSystem.requestRenderVisuals(input);
|
|
38
40
|
},
|
|
39
|
-
|
|
41
|
+
completeCoreDragTo(target) {
|
|
40
42
|
const internalState = state();
|
|
41
43
|
const mutationSession = internalState.mutation.getSession();
|
|
42
44
|
const interaction = internalState.state.interaction;
|
|
43
45
|
const dragSession = interaction.dragSession;
|
|
44
|
-
assert(dragSession !== null, '
|
|
45
|
-
assert(dragSession
|
|
46
|
+
assert(dragSession !== null, 'completeDragTo requires an active drag session');
|
|
47
|
+
assert(isDragSessionCoreOwned(dragSession), 'completeDragTo can only be called for core-owned drag sessions');
|
|
46
48
|
uiMoveCompleteTo(internalState, target);
|
|
47
|
-
mutationSession.addMutation('runtime.interaction.
|
|
49
|
+
mutationSession.addMutation('runtime.interaction.completeDragTo', true, dragSession);
|
|
48
50
|
runtimeRunMutationPipeline(internalState);
|
|
49
51
|
},
|
|
50
|
-
|
|
52
|
+
completeExtensionDrag(target) {
|
|
51
53
|
const internalState = state();
|
|
52
54
|
const mutationSession = internalState.mutation.getSession();
|
|
53
55
|
const interaction = internalState.state.interaction;
|
|
54
56
|
const dragSession = interaction.dragSession;
|
|
55
|
-
assert(dragSession !== null, '
|
|
56
|
-
assert(dragSession
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
assert(dragSession !== null, 'completeExtensionDrag requires an active drag session');
|
|
58
|
+
assert(!isDragSessionCoreOwned(dragSession), 'completeExtensionDrag can only be called for extension-owned drag sessions');
|
|
59
|
+
assert(dragSession.targetSquare === target, 'The target square in completeExtensionDrag must match the current target square of the drag session');
|
|
60
|
+
internalState.extensionSystem.completeDrag(dragSession);
|
|
61
|
+
internalState.state.interaction.setDragSession(null, mutationSession);
|
|
60
62
|
},
|
|
61
63
|
startReleaseTargetingDrag(source, target) {
|
|
62
64
|
const internalState = state();
|
|
@@ -65,6 +67,7 @@ export function createRuntimeInteractionSurface(state) {
|
|
|
65
67
|
assert(interaction.selected !== null, 'startReleaseTargetingDrag requires a selected piece');
|
|
66
68
|
assert(interaction.selected.square === source, 'startReleaseTargetingDrag source must match selected square');
|
|
67
69
|
const dragSession = {
|
|
70
|
+
owner: 'core',
|
|
68
71
|
type: 'release-targeting',
|
|
69
72
|
sourceSquare: source,
|
|
70
73
|
sourcePieceCode: interaction.selected.pieceCode,
|
|
@@ -93,6 +96,10 @@ export function createRuntimeInteractionSurface(state) {
|
|
|
93
96
|
assert(currentDragSession !== null, 'No active drag session to update');
|
|
94
97
|
internalState.state.interaction.updateDragSessionCurrentTarget(target, interactionMutationSession);
|
|
95
98
|
runtimeRunMutationPipeline(internalState);
|
|
99
|
+
},
|
|
100
|
+
onEvent(context) {
|
|
101
|
+
const internalState = state();
|
|
102
|
+
internalState.extensionSystem.onEvent(context);
|
|
96
103
|
}
|
|
97
104
|
};
|
|
98
105
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { Runtime, RuntimeInitOptions } from '../types/main';
|
|
1
|
+
import type { Runtime, RuntimeInitOptions } from '../types/main.js';
|
|
2
2
|
export declare function createRuntime(options: RuntimeInitOptions): Runtime;
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import assert from '@ktarmyshov/assert';
|
|
2
|
-
import { createExtensionSystem } from '../../extensions/factory/main';
|
|
3
|
-
import { assertFrameRenderable } from '../../extensions/types/basic/update';
|
|
4
|
-
import { createLayout } from '../../layout/factory';
|
|
5
|
-
import { createRenderSystem } from '../../render/factory';
|
|
6
|
-
import { isNonEmptyPieceCode } from '../../state/board/check';
|
|
7
|
-
import { normalizeSquare } from '../../state/board/normalize';
|
|
8
|
-
import { createRuntimeState } from '../../state/factory';
|
|
9
|
-
import { createInteractionController } from '../input/controller/factory';
|
|
10
|
-
import { runtimeDestroy, runtimeMount, runtimeUnmount } from '../lifecycle';
|
|
11
|
-
import { createRuntimeMutationPipeline } from '../mutation/factory';
|
|
12
|
-
import { runtimeRunMutationPipeline } from '../mutation/run';
|
|
13
|
-
import {
|
|
2
|
+
import { createExtensionSystem } from '../../extensions/factory/main.js';
|
|
3
|
+
import { assertFrameRenderable } from '../../extensions/types/basic/update.js';
|
|
4
|
+
import { createLayout } from '../../layout/factory.js';
|
|
5
|
+
import { createRenderSystem } from '../../render/factory.js';
|
|
6
|
+
import { isNonEmptyPieceCode } from '../../state/board/check.js';
|
|
7
|
+
import { normalizeSquare } from '../../state/board/normalize.js';
|
|
8
|
+
import { createRuntimeState } from '../../state/factory.js';
|
|
9
|
+
import { createInteractionController } from '../input/controller/factory.js';
|
|
10
|
+
import { runtimeDestroy, runtimeMount, runtimeUnmount } from '../lifecycle.js';
|
|
11
|
+
import { createRuntimeMutationPipeline } from '../mutation/factory.js';
|
|
12
|
+
import { runtimeRunMutationPipeline } from '../mutation/run.js';
|
|
13
|
+
import { createExtensionRuntimeSurfaceEvents } from './events.js';
|
|
14
|
+
import { createRuntimeInteractionSurface } from './input.js';
|
|
14
15
|
function createRuntimeInternal(options) {
|
|
15
16
|
const extensionSystem = createExtensionSystem(options);
|
|
16
17
|
const render = createRenderSystem({
|
|
@@ -30,7 +31,7 @@ function createRuntimeInternal(options) {
|
|
|
30
31
|
})
|
|
31
32
|
};
|
|
32
33
|
}
|
|
33
|
-
function
|
|
34
|
+
function createExtensionRuntimeSurfaceCommandsInternalSurface(getInternalState) {
|
|
34
35
|
return {
|
|
35
36
|
setPosition(input) {
|
|
36
37
|
const state = getInternalState();
|
|
@@ -103,6 +104,13 @@ function createExtensionRuntimeSurfaceCommands(getInternalState) {
|
|
|
103
104
|
runtimeRunMutationPipeline(state);
|
|
104
105
|
return changed;
|
|
105
106
|
},
|
|
107
|
+
startDrag(session) {
|
|
108
|
+
const state = getInternalState();
|
|
109
|
+
const mutationSession = state.mutation.getSession();
|
|
110
|
+
const changed = state.state.interaction.setDragSession(session, mutationSession);
|
|
111
|
+
runtimeRunMutationPipeline(state);
|
|
112
|
+
return changed;
|
|
113
|
+
},
|
|
106
114
|
clearActiveInteraction() {
|
|
107
115
|
const state = getInternalState();
|
|
108
116
|
const mutationSession = state.mutation.getSession();
|
|
@@ -117,6 +125,36 @@ function createExtensionRuntimeSurfaceCommands(getInternalState) {
|
|
|
117
125
|
runtimeRunMutationPipeline(state);
|
|
118
126
|
return changed;
|
|
119
127
|
},
|
|
128
|
+
resolveDeferredUIMoveRequest(details) {
|
|
129
|
+
const state = getInternalState();
|
|
130
|
+
const deferredRequest = state.state.change.deferredUIMoveRequest;
|
|
131
|
+
assert(deferredRequest, 'No deferred UI move request to resolve');
|
|
132
|
+
const { sourceSquare, destination } = deferredRequest;
|
|
133
|
+
const moveRequest = {
|
|
134
|
+
from: sourceSquare,
|
|
135
|
+
to: destination.to,
|
|
136
|
+
...(destination.capturedSquare !== undefined && {
|
|
137
|
+
capturedSquare: destination.capturedSquare
|
|
138
|
+
}),
|
|
139
|
+
...(destination.secondary !== undefined && { secondary: destination.secondary }),
|
|
140
|
+
promotedTo: details.promotedTo
|
|
141
|
+
};
|
|
142
|
+
const mutationSession = state.mutation.getSession();
|
|
143
|
+
const move = state.state.board.move(moveRequest, mutationSession);
|
|
144
|
+
state.state.change.setDeferredUIMoveRequest(null, mutationSession);
|
|
145
|
+
mutationSession.addMutation('runtime.interaction.resolveDeferredUIMoveRequest', true);
|
|
146
|
+
runtimeRunMutationPipeline(state);
|
|
147
|
+
return move;
|
|
148
|
+
},
|
|
149
|
+
cancelDeferredUIMoveRequest() {
|
|
150
|
+
const state = getInternalState();
|
|
151
|
+
assert(state.state.change.deferredUIMoveRequest, 'No deferred UI move request to cancel');
|
|
152
|
+
const mutationSession = state.mutation.getSession();
|
|
153
|
+
const changed = state.state.change.setDeferredUIMoveRequest(null, mutationSession);
|
|
154
|
+
mutationSession.addMutation('runtime.interaction.cancelDeferredUIMoveRequest', changed);
|
|
155
|
+
runtimeRunMutationPipeline(state);
|
|
156
|
+
return changed;
|
|
157
|
+
},
|
|
120
158
|
getSnapshot() {
|
|
121
159
|
const state = getInternalState();
|
|
122
160
|
return {
|
|
@@ -139,11 +177,13 @@ export function createRuntime(options) {
|
|
|
139
177
|
return internalState;
|
|
140
178
|
}
|
|
141
179
|
// Create RuntimeExtensionSurface to pass to the extension system for initialization of extension instances
|
|
142
|
-
const
|
|
180
|
+
const extensionSurfaceCommands = createExtensionRuntimeSurfaceCommandsInternalSurface(getInternalState);
|
|
181
|
+
const extensionSurfaceEvents = createExtensionRuntimeSurfaceEvents(getInternalState);
|
|
143
182
|
// Now construct the internal state
|
|
144
183
|
const optionsInternal = {
|
|
145
184
|
...options,
|
|
146
|
-
extensionRuntimeSurfaceCommands:
|
|
185
|
+
extensionRuntimeSurfaceCommands: extensionSurfaceCommands,
|
|
186
|
+
extensionRuntimeSurfaceEvents: extensionSurfaceEvents,
|
|
147
187
|
getInternalState
|
|
148
188
|
};
|
|
149
189
|
internalState = createRuntimeInternal(optionsInternal);
|
|
@@ -174,7 +214,7 @@ export function createRuntime(options) {
|
|
|
174
214
|
internalStatus = 'destroyed';
|
|
175
215
|
internalState = null;
|
|
176
216
|
},
|
|
177
|
-
...
|
|
217
|
+
...extensionSurfaceCommands,
|
|
178
218
|
getExtensionsPublicRecord() {
|
|
179
219
|
return getInternalState().extensionSystem.getPublicRecord();
|
|
180
220
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ALL_SCENE_POINTER_EVENT_TYPES } from '../../../extensions/types/basic/events.js';
|
|
2
|
+
import { pointerEventDestroy, pointerEventHandler } from './pointer.js';
|
|
3
|
+
export function eventHandler(state, e) {
|
|
4
|
+
let context = null;
|
|
5
|
+
if (ALL_SCENE_POINTER_EVENT_TYPES.has(e.type)) {
|
|
6
|
+
context = pointerEventHandler(state, e);
|
|
7
|
+
}
|
|
8
|
+
if (!context) {
|
|
9
|
+
context = {
|
|
10
|
+
rawEvent: e,
|
|
11
|
+
sceneEvent: null
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
// Pass to controller for extension handling
|
|
15
|
+
state.controller.onEvent(context);
|
|
16
|
+
}
|
|
17
|
+
export function eventDestroy(state) {
|
|
18
|
+
pointerEventDestroy(state);
|
|
19
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { InputAdapter, InputAdapterInitOptions } from './types';
|
|
1
|
+
import { InputAdapter, InputAdapterInitOptions } from './types.js';
|
|
2
2
|
export declare function createInputAdapter(options: InputAdapterInitOptions): InputAdapter;
|
|
@@ -1,55 +1,36 @@
|
|
|
1
|
-
import
|
|
1
|
+
import assert from '@ktarmyshov/assert';
|
|
2
|
+
import { eventDestroy, eventHandler } from './event.js';
|
|
3
|
+
import { NEED_EVENT_TYPES } from './types.js';
|
|
2
4
|
function createInputAdapterInternal(options) {
|
|
3
5
|
return {
|
|
4
6
|
container: options.container,
|
|
5
|
-
|
|
7
|
+
getRenderGeometry: options.getRenderGeometry,
|
|
6
8
|
controller: options.controller,
|
|
7
9
|
activePointerId: null
|
|
8
10
|
};
|
|
9
11
|
}
|
|
10
12
|
export function createInputAdapter(options) {
|
|
11
13
|
const internalState = createInputAdapterInternal(options);
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
return;
|
|
15
|
-
onPointerDown(internalState, e);
|
|
16
|
-
};
|
|
17
|
-
const onPointerMoveHandler = (e) => {
|
|
18
|
-
if (!isPointerRelevantEvent(e))
|
|
19
|
-
return;
|
|
20
|
-
onPointerMove(internalState, e);
|
|
21
|
-
};
|
|
22
|
-
const onPointerUpHandler = (e) => {
|
|
23
|
-
if (!isPointerRelevantEvent(e))
|
|
24
|
-
return;
|
|
25
|
-
onPointerUp(internalState, e);
|
|
26
|
-
};
|
|
27
|
-
const onPointerCancelHandler = (e) => {
|
|
28
|
-
if (!isPointerRelevantEvent(e))
|
|
29
|
-
return;
|
|
30
|
-
onPointerCancel(internalState, e);
|
|
31
|
-
};
|
|
32
|
-
const onPointerLeaveHandler = (e) => {
|
|
33
|
-
if (!isPointerRelevantEvent(e))
|
|
34
|
-
return;
|
|
35
|
-
onPointerLeave(internalState, e);
|
|
14
|
+
const onEventHander = (e) => {
|
|
15
|
+
eventHandler(internalState, e);
|
|
36
16
|
};
|
|
37
17
|
const inputAdapter = {
|
|
18
|
+
subscribeEvent(type) {
|
|
19
|
+
internalState.container.addEventListener(type, onEventHander);
|
|
20
|
+
},
|
|
21
|
+
unsubscribeEvent(type) {
|
|
22
|
+
assert(NEED_EVENT_TYPES.has(type), `Unsubscribe for event type ${type} is not supported. This is required event type for the board to function properly.`);
|
|
23
|
+
internalState.container.removeEventListener(type, onEventHander);
|
|
24
|
+
},
|
|
38
25
|
destroy() {
|
|
39
|
-
|
|
40
|
-
|
|
26
|
+
for (const type of NEED_EVENT_TYPES) {
|
|
27
|
+
internalState.container.removeEventListener(type, onEventHander);
|
|
41
28
|
}
|
|
42
|
-
internalState
|
|
43
|
-
internalState.container.removeEventListener('pointermove', onPointerMoveHandler);
|
|
44
|
-
internalState.container.removeEventListener('pointerup', onPointerUpHandler);
|
|
45
|
-
internalState.container.removeEventListener('pointercancel', onPointerCancelHandler);
|
|
46
|
-
internalState.container.removeEventListener('pointerleave', onPointerLeaveHandler);
|
|
29
|
+
eventDestroy(internalState);
|
|
47
30
|
}
|
|
48
31
|
};
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
internalState.container.addEventListener('pointercancel', onPointerCancelHandler);
|
|
53
|
-
internalState.container.addEventListener('pointerleave', onPointerLeaveHandler);
|
|
32
|
+
for (const type of NEED_EVENT_TYPES) {
|
|
33
|
+
internalState.container.addEventListener(type, onEventHander);
|
|
34
|
+
}
|
|
54
35
|
return inputAdapter;
|
|
55
36
|
}
|