@mirasen/chessboard 1.1.5 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/README.md +1 -1
  3. package/dist/animation/render/fade.d.ts +2 -3
  4. package/dist/animation/render/fade.js +6 -6
  5. package/dist/animation/render/move.d.ts +2 -3
  6. package/dist/animation/render/move.js +6 -6
  7. package/dist/animation/render/plan.d.ts +3 -4
  8. package/dist/animation/render/plan.js +5 -5
  9. package/dist/animation/render/static.d.ts +2 -3
  10. package/dist/animation/render/static.js +4 -4
  11. package/dist/animation/render/types.d.ts +10 -4
  12. package/dist/extensions/build/index.d.ts +1 -2
  13. package/dist/extensions/build/index.js +1 -1
  14. package/dist/extensions/factory/main.js +11 -7
  15. package/dist/extensions/factory/runtime.js +24 -1
  16. package/dist/extensions/first-party/active-target/factory.js +18 -11
  17. package/dist/extensions/first-party/annotations/api.d.ts +16 -0
  18. package/dist/extensions/first-party/annotations/api.js +79 -0
  19. package/dist/extensions/first-party/annotations/committed.d.ts +3 -0
  20. package/dist/extensions/first-party/annotations/committed.js +11 -0
  21. package/dist/extensions/first-party/annotations/constants.d.ts +3 -0
  22. package/dist/extensions/first-party/annotations/constants.js +54 -0
  23. package/dist/extensions/first-party/annotations/denormalize.d.ts +4 -0
  24. package/dist/extensions/first-party/annotations/denormalize.js +22 -0
  25. package/dist/extensions/first-party/annotations/factory.d.ts +3 -0
  26. package/dist/extensions/first-party/annotations/factory.js +143 -0
  27. package/dist/extensions/first-party/annotations/interaction.d.ts +8 -0
  28. package/dist/extensions/first-party/annotations/interaction.js +129 -0
  29. package/dist/extensions/first-party/annotations/invalidation.d.ts +3 -0
  30. package/dist/extensions/first-party/annotations/invalidation.js +7 -0
  31. package/dist/extensions/first-party/annotations/normalize.d.ts +12 -0
  32. package/dist/extensions/first-party/annotations/normalize.js +54 -0
  33. package/dist/extensions/first-party/annotations/render/committed.d.ts +3 -0
  34. package/dist/extensions/first-party/annotations/render/committed.js +123 -0
  35. package/dist/extensions/first-party/annotations/render/helpers/arrows.d.ts +33 -0
  36. package/dist/extensions/first-party/annotations/render/helpers/arrows.js +93 -0
  37. package/dist/extensions/first-party/annotations/render/helpers/circles.d.ts +18 -0
  38. package/dist/extensions/first-party/annotations/render/helpers/circles.js +30 -0
  39. package/dist/extensions/first-party/annotations/render/preview.d.ts +3 -0
  40. package/dist/extensions/first-party/annotations/render/preview.js +96 -0
  41. package/dist/extensions/first-party/annotations/types/internal.d.ts +77 -0
  42. package/dist/extensions/first-party/annotations/types/internal.js +1 -0
  43. package/dist/extensions/first-party/annotations/types/main.d.ts +40 -0
  44. package/dist/extensions/first-party/annotations/types/main.js +6 -0
  45. package/dist/extensions/first-party/annotations/types/public.d.ts +48 -0
  46. package/dist/extensions/first-party/annotations/types/public.js +1 -0
  47. package/dist/extensions/first-party/annotations/update.d.ts +3 -0
  48. package/dist/extensions/first-party/annotations/update.js +45 -0
  49. package/dist/extensions/first-party/auto-promote/factory.js +6 -6
  50. package/dist/extensions/first-party/board-events/factory.js +6 -6
  51. package/dist/extensions/first-party/common/helpers.d.ts +2 -1
  52. package/dist/extensions/first-party/common/helpers.js +6 -5
  53. package/dist/extensions/first-party/common/types.d.ts +2 -0
  54. package/dist/extensions/first-party/last-move/factory.js +9 -9
  55. package/dist/extensions/first-party/legal-moves/factory.js +8 -8
  56. package/dist/extensions/first-party/main-renderer/animation/factory.d.ts +2 -2
  57. package/dist/extensions/first-party/main-renderer/animation/factory.js +4 -4
  58. package/dist/extensions/first-party/main-renderer/animation/render.d.ts +1 -1
  59. package/dist/extensions/first-party/main-renderer/animation/render.js +2 -2
  60. package/dist/extensions/first-party/main-renderer/animation/types.d.ts +3 -3
  61. package/dist/extensions/first-party/main-renderer/board/factory.js +2 -2
  62. package/dist/extensions/first-party/main-renderer/board/render.d.ts +1 -1
  63. package/dist/extensions/first-party/main-renderer/board/render.js +4 -4
  64. package/dist/extensions/first-party/main-renderer/board/types.d.ts +1 -1
  65. package/dist/extensions/first-party/main-renderer/coordinates/factory.js +2 -2
  66. package/dist/extensions/first-party/main-renderer/coordinates/render.d.ts +1 -1
  67. package/dist/extensions/first-party/main-renderer/coordinates/render.js +5 -5
  68. package/dist/extensions/first-party/main-renderer/coordinates/types.d.ts +1 -1
  69. package/dist/extensions/first-party/main-renderer/drag/factory.d.ts +2 -2
  70. package/dist/extensions/first-party/main-renderer/drag/factory.js +11 -8
  71. package/dist/extensions/first-party/main-renderer/drag/render.d.ts +1 -1
  72. package/dist/extensions/first-party/main-renderer/drag/render.js +7 -6
  73. package/dist/extensions/first-party/main-renderer/drag/types.d.ts +6 -5
  74. package/dist/extensions/first-party/main-renderer/drag/update.js +2 -2
  75. package/dist/extensions/first-party/main-renderer/factory.js +9 -5
  76. package/dist/extensions/first-party/main-renderer/piece-symbols.d.ts +19 -0
  77. package/dist/extensions/first-party/main-renderer/piece-symbols.js +45 -0
  78. package/dist/extensions/first-party/main-renderer/pieces/factory.d.ts +2 -2
  79. package/dist/extensions/first-party/main-renderer/pieces/factory.js +4 -4
  80. package/dist/extensions/first-party/main-renderer/pieces/render.d.ts +1 -1
  81. package/dist/extensions/first-party/main-renderer/pieces/render.js +8 -8
  82. package/dist/extensions/first-party/main-renderer/pieces/types.d.ts +4 -4
  83. package/dist/extensions/first-party/main-renderer/types/extension.d.ts +1 -1
  84. package/dist/extensions/first-party/main-renderer/types/extension.js +8 -1
  85. package/dist/extensions/first-party/main-renderer/types/instance.d.ts +2 -0
  86. package/dist/extensions/first-party/promotion/factory.js +10 -10
  87. package/dist/extensions/first-party/selected-square/factory.js +8 -8
  88. package/dist/extensions/first-party/watermark/factory.js +8 -8
  89. package/dist/extensions/types/basic/events.d.ts +32 -3
  90. package/dist/extensions/types/basic/events.js +2 -1
  91. package/dist/extensions/types/basic/mount.d.ts +5 -2
  92. package/dist/extensions/types/basic/mount.js +0 -2
  93. package/dist/extensions/types/basic/transient-visuals.d.ts +1 -1
  94. package/dist/extensions/types/context/animation.d.ts +3 -3
  95. package/dist/extensions/types/context/events.d.ts +2 -1
  96. package/dist/extensions/types/context/update.d.ts +6 -7
  97. package/dist/extensions/types/extension.d.ts +3 -0
  98. package/dist/extensions/types/main.d.ts +1 -0
  99. package/dist/extensions/types/surface/commands.d.ts +1 -1
  100. package/dist/extensions/types/surface/main.d.ts +6 -4
  101. package/dist/extensions/types/wrapper.d.ts +3 -1
  102. package/dist/extensions/types/wrapper.js +6 -2
  103. package/dist/extensions/update.js +6 -10
  104. package/dist/index.d.ts +1 -1
  105. package/dist/render/mount.js +3 -3
  106. package/dist/render/rendering/state.js +2 -2
  107. package/dist/render/svg/factory.js +40 -25
  108. package/dist/render/svg/helpers.d.ts +8 -4
  109. package/dist/render/svg/helpers.js +27 -12
  110. package/dist/render/svg/ids.d.ts +6 -0
  111. package/dist/render/svg/ids.js +11 -0
  112. package/dist/render/types.d.ts +4 -3
  113. package/dist/render/types.js +2 -1
  114. package/dist/runtime/factory/input.d.ts +3 -1
  115. package/dist/runtime/factory/input.js +11 -2
  116. package/dist/runtime/factory/main.js +10 -4
  117. package/dist/runtime/input/adapter/event.js +2 -2
  118. package/dist/runtime/input/adapter/pointer.d.ts +2 -2
  119. package/dist/runtime/input/controller/factory.d.ts +1 -1
  120. package/dist/runtime/input/controller/factory.js +35 -15
  121. package/dist/runtime/input/controller/helpers.d.ts +1 -1
  122. package/dist/runtime/input/controller/interaction.d.ts +3 -0
  123. package/dist/runtime/input/controller/interaction.js +14 -0
  124. package/dist/runtime/input/controller/pointer.d.ts +6 -6
  125. package/dist/runtime/input/controller/pointer.js +53 -27
  126. package/dist/runtime/input/controller/transient-visuals.d.ts +2 -3
  127. package/dist/runtime/input/controller/types.d.ts +6 -5
  128. package/dist/runtime/types/main.d.ts +1 -1
  129. package/dist/wrapper/factory.js +2 -7
  130. package/dist/wrapper/types.d.ts +3 -11
  131. package/package.json +1 -3
@@ -1,7 +1,7 @@
1
- import { Square } from '../../../state/board/types/internal.js';
2
- import { ScenePoint } from '../basic/transient-visuals.js';
1
+ import type { Square } from '../../../state/board/types/internal.js';
2
+ import type { ScenePoint } from '../basic/transient-visuals.js';
3
3
  export interface ScenePointerEvent {
4
- readonly type: 'pointercancel' | 'pointerdown' | 'pointerenter' | 'pointerleave' | 'pointermove' | 'pointerout' | 'pointerover' | 'pointerrawupdate' | 'pointerup';
4
+ readonly type: 'pointercancel' | 'pointerdown' | 'pointerenter' | 'pointerleave' | 'pointermove' | 'pointerout' | 'pointerover' | 'pointerrawupdate' | 'pointerup' | 'contextmenu';
5
5
  readonly point: ScenePoint;
6
6
  readonly clampedPoint: ScenePoint;
7
7
  readonly boardClampedPoint: ScenePoint | null;
@@ -9,3 +9,32 @@ export interface ScenePointerEvent {
9
9
  }
10
10
  export declare const ALL_SCENE_POINTER_EVENT_TYPES: ReadonlySet<string>;
11
11
  export type SceneEvent = ScenePointerEvent;
12
+ export type RuntimeInteractionActionStartLiftedDrag = {
13
+ type: 'startLiftedDrag';
14
+ source: Square;
15
+ target: Square;
16
+ };
17
+ export type RuntimeInteractionActionStartReleaseTargetingDrag = {
18
+ type: 'startReleaseTargetingDrag';
19
+ source: Square;
20
+ target: Square;
21
+ };
22
+ export type RuntimeInteractionActionCompleteCoreDrag = {
23
+ type: 'completeCoreDragTo';
24
+ target: Square;
25
+ };
26
+ export type RuntimeInteractionActionCompleteExtensionDrag = {
27
+ type: 'completeExtensionDrag';
28
+ target: Square | null;
29
+ };
30
+ export type RuntimeInteractionActionUpdateDragSessionCurrentTarget = {
31
+ type: 'updateDragSessionCurrentTarget';
32
+ target: Square | null;
33
+ };
34
+ export type RuntimeInteractionActionCancelActiveInteraction = {
35
+ type: 'cancelActiveInteraction';
36
+ };
37
+ export type RuntimeInteractionActionCancelInteraction = {
38
+ type: 'cancelInteraction';
39
+ };
40
+ export type RuntimeInteractionAction = RuntimeInteractionActionStartLiftedDrag | RuntimeInteractionActionStartReleaseTargetingDrag | RuntimeInteractionActionCompleteCoreDrag | RuntimeInteractionActionCompleteExtensionDrag | RuntimeInteractionActionUpdateDragSessionCurrentTarget | RuntimeInteractionActionCancelActiveInteraction | RuntimeInteractionActionCancelInteraction;
@@ -7,5 +7,6 @@ export const ALL_SCENE_POINTER_EVENT_TYPES = new Set([
7
7
  'pointerout',
8
8
  'pointerover',
9
9
  'pointerrawupdate',
10
- 'pointerup'
10
+ 'pointerup',
11
+ 'contextmenu'
11
12
  ]);
@@ -1,6 +1,9 @@
1
- export type ExtensionSlotName = 'defs' | 'board' | 'coordinates' | 'underPieces' | 'pieces' | 'overPieces' | 'animation' | 'underDrag' | 'drag' | 'overDrag';
2
1
  export declare const ALL_EXTENSION_SLOTS: readonly ["defs", "board", "coordinates", "underPieces", "pieces", "overPieces", "animation", "underDrag", "drag", "overDrag"];
3
- export type ExtensionSlotSvgRoots<TSlots extends readonly ExtensionSlotName[]> = Readonly<Record<TSlots[number], SVGGElement>>;
2
+ export type ExtensionSlotName = (typeof ALL_EXTENSION_SLOTS)[number];
3
+ export type ExtensionSlotSvgRoot<TSlot extends ExtensionSlotName> = TSlot extends 'defs' ? SVGDefsElement : SVGGElement;
4
+ export type ExtensionSlotSvgRoots<TSlots extends readonly ExtensionSlotName[]> = Readonly<{
5
+ [TSlot in TSlots[number]]: ExtensionSlotSvgRoot<TSlot>;
6
+ }>;
4
7
  export type ExtensionAllocatedSlotsInternal = Partial<ExtensionSlotSvgRoots<readonly ExtensionSlotName[]>>;
5
8
  export interface ExtensionInstanceMountOptions<TSlots extends readonly ExtensionSlotName[]> {
6
9
  slotRoots: ExtensionSlotSvgRoots<TSlots>;
@@ -10,5 +10,3 @@ export const ALL_EXTENSION_SLOTS = [
10
10
  'drag',
11
11
  'overDrag'
12
12
  ];
13
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
14
- const _checkAllExtensionSlotsExact = true;
@@ -1,4 +1,4 @@
1
- import { Square } from '../../../state/board/types/internal.js';
1
+ import type { Square } from '../../../state/board/types/internal.js';
2
2
  export interface ScenePoint {
3
3
  readonly x: number;
4
4
  readonly y: number;
@@ -1,6 +1,6 @@
1
- import { ExtensionInvalidationState } from '../../invalidation/types.js';
2
- import { ExtensionAnimationSession } from '../basic/animation.js';
3
- import { ExtensionRenderContext } from './render.js';
1
+ import type { ExtensionInvalidationState } from '../../invalidation/types.js';
2
+ import type { ExtensionAnimationSession } from '../basic/animation.js';
3
+ import type { ExtensionRenderContext } from './render.js';
4
4
  export interface ExtensionSubmittedAnimationSession extends ExtensionAnimationSession {
5
5
  readonly status: 'submitted';
6
6
  }
@@ -1,5 +1,6 @@
1
- import { SceneEvent } from '../basic/events.js';
1
+ import type { RuntimeInteractionAction, SceneEvent } from '../basic/events.js';
2
2
  export interface ExtensionOnEventContext {
3
3
  rawEvent: Event;
4
4
  sceneEvent: SceneEvent | null;
5
+ runtimeInteractionActionPreview: RuntimeInteractionAction | null;
5
6
  }
@@ -1,11 +1,12 @@
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';
1
+ import type { RuntimeReadonlyMutationSession } from '../../../runtime/mutation/types.js';
2
+ import type { ExtensionInvalidationState } from '../../invalidation/types.js';
3
+ import type { RenderFrameSnapshot } from '../basic/render.js';
4
+ import type { UpdateFrameSnapshot, UpdateFrameSnapshotMounted, UpdateFrameSnapshotUnmounted } from '../basic/update.js';
5
5
  export interface ExtensionUpdateContextCommon {
6
6
  readonly previousFrame: UpdateFrameSnapshot | null;
7
7
  readonly mutation: RuntimeReadonlyMutationSession;
8
8
  readonly currentFrame: UpdateFrameSnapshot;
9
+ readonly invalidation: ExtensionInvalidationState;
9
10
  }
10
11
  export interface ExtensionUpdateContextCommonUnmounted extends ExtensionUpdateContextCommon {
11
12
  readonly currentFrame: UpdateFrameSnapshotUnmounted;
@@ -14,9 +15,7 @@ export interface ExtensionUpdateContextCommonMounted extends ExtensionUpdateCont
14
15
  readonly currentFrame: UpdateFrameSnapshotMounted;
15
16
  }
16
17
  export type ExtensionUpdateContextUnmounted = ExtensionUpdateContextCommonUnmounted;
17
- export interface ExtensionUpdateContextMounted extends ExtensionUpdateContextCommonMounted {
18
- readonly invalidation: ExtensionInvalidationState;
19
- }
18
+ export type ExtensionUpdateContextMounted = ExtensionUpdateContextCommonMounted;
20
19
  export type ExtensionUpdateContext = ExtensionUpdateContextUnmounted | ExtensionUpdateContextMounted;
21
20
  export declare function isUpdateContextCommonMounted<T extends ExtensionUpdateContextCommon>(context: T): context is T & ExtensionUpdateContextCommonMounted;
22
21
  export declare function isUpdateContextMounted<T extends ExtensionUpdateContext>(context: T): context is T & ExtensionUpdateContextMounted;
@@ -1,3 +1,4 @@
1
+ import type { SvgIdResolver } from '../../render/svg/ids.js';
1
2
  import { ExtensionDragSessionSnapshot } from './basic/interaction.js';
2
3
  import { ExtensionInstanceMountOptions, ExtensionSlotName } from './basic/mount.js';
3
4
  import { ExtensionAnimationFinishedContext, ExtensionCleanAnimationContext, ExtensionPrepareAnimationContext, ExtensionRenderAnimationContext } from './context/animation.js';
@@ -19,6 +20,7 @@ interface ExtensionInstanceBase<TId extends string, TSlots extends readonly Exte
19
20
  onAnimationFinished?(context: ExtensionAnimationFinishedContext): void;
20
21
  cleanAnimation?(context: ExtensionCleanAnimationContext): void;
21
22
  completeDrag?(session: ExtensionDragSessionSnapshot): void;
23
+ cancelDrag?(session: ExtensionDragSessionSnapshot): void;
22
24
  renderTransientVisuals?(context: ExtensionRenderTransientVisualsContext): void;
23
25
  onUIMoveRequest?(context: ExtensionPendingUIMoveRequestContext): void;
24
26
  onEvent?(context: ExtensionOnEventContext): void;
@@ -30,6 +32,7 @@ export type ExtensionInstance<TId extends string, TSlots extends readonly Extens
30
32
  export type AnyExtensionInstance = ExtensionInstance<string, readonly ExtensionSlotName[], unknown>;
31
33
  export interface ExtensionCreateInstanceOptions {
32
34
  runtimeSurface: ExtensionRuntimeSurface;
35
+ svgIds: SvgIdResolver;
33
36
  }
34
37
  export interface ExtensionDefinition<TId extends string, TSlots extends readonly ExtensionSlotName[], TPublic> {
35
38
  readonly id: TId;
@@ -43,6 +43,7 @@ export interface ExtensionSystem {
43
43
  onUIMoveRequest(context: ExtensionPendingUIMoveRequestContext): void;
44
44
  onEvent(context: ExtensionOnEventContext): void;
45
45
  completeDrag(session: DragSessionExtensionOwned): void;
46
+ cancelDrag(session: DragSessionExtensionOwned): void;
46
47
  onUnmount(): void;
47
48
  onDestroy(): void;
48
49
  }
@@ -27,7 +27,7 @@ export interface ExtensionRuntimeSurfaceCommands {
27
27
  clearInteraction(): boolean;
28
28
  resolveDeferredUIMoveRequest(details: DeferredUIMoveResolutionDetails): Move;
29
29
  cancelDeferredUIMoveRequest(): boolean;
30
- requestRender(request: ExtensionRuntimeSurfaceCommandsRenderRequest): void;
30
+ requestRender(request: ExtensionRuntimeSurfaceCommandsRenderRequest): boolean;
31
31
  getSnapshot(): ExtensionRuntimeSurfaceCommandsSnapshot;
32
32
  }
33
33
  export interface ExtensionRuntimeSurfaceCommandsInternalSurface extends ExtensionRuntimeSurfaceCommands {
@@ -1,10 +1,12 @@
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';
1
+ import type { ExtensionInvalidationState } from '../../invalidation/types.js';
2
+ import type { ExtensionAnimationController } from '../basic/animation.js';
3
+ import type { ExtensionRuntimeSurfaceCommands } from './commands.js';
4
+ import type { ExtensionRuntimeSurfaceEvents } from './events.js';
5
+ import type { ExtensionRuntimeSurfaceTransientVisuals } from './transient-visuals.js';
5
6
  export interface ExtensionRuntimeSurface {
6
7
  readonly commands: ExtensionRuntimeSurfaceCommands;
7
8
  readonly animation: ExtensionAnimationController;
8
9
  readonly events: ExtensionRuntimeSurfaceEvents;
9
10
  readonly transientVisuals: ExtensionRuntimeSurfaceTransientVisuals;
11
+ readonly invalidation: ExtensionInvalidationState;
10
12
  }
@@ -1,4 +1,5 @@
1
1
  import { createActiveTarget } from '../first-party/active-target/factory.js';
2
+ import { createAnnotations } from '../first-party/annotations/factory.js';
2
3
  import { createAutoPromote } from '../first-party/auto-promote/factory.js';
3
4
  import { createBoardEvents } from '../first-party/board-events/factory.js';
4
5
  import { createLastMove } from '../first-party/last-move/factory.js';
@@ -17,10 +18,11 @@ export declare const builtInExtensionFactoryMap: {
17
18
  events: typeof createBoardEvents;
18
19
  autoPromote: typeof createAutoPromote;
19
20
  promotion: typeof createPromotion;
21
+ annotations: typeof createAnnotations;
20
22
  };
21
23
  export type BuiltInExtensionId = keyof typeof builtInExtensionFactoryMap;
22
24
  export type BuiltInExtensionDefinitionMap = {
23
25
  [Id in BuiltInExtensionId]: ReturnType<(typeof builtInExtensionFactoryMap)[Id]>;
24
26
  };
25
- export declare const DefaultBuiltinChessboardExtensions: readonly ["renderer", "watermark", "selectedSquare", "lastMove", "activeTarget", "legalMoves", "events", "autoPromote", "promotion"];
27
+ export declare const DefaultBuiltinChessboardExtensions: readonly ["renderer", "watermark", "selectedSquare", "lastMove", "activeTarget", "legalMoves", "events", "autoPromote", "promotion", "annotations"];
26
28
  export type DefaultBuiltinChessboardExtensions = typeof DefaultBuiltinChessboardExtensions;
@@ -1,5 +1,7 @@
1
1
  import { createActiveTarget } from '../first-party/active-target/factory.js';
2
2
  import { EXTENSION_ID as EXTENSION_ID_ACTIVE_TARGET } from '../first-party/active-target/types.js';
3
+ import { createAnnotations } from '../first-party/annotations/factory.js';
4
+ import { EXTENSION_ID as EXTENSION_ID_ANNOTATIONS } from '../first-party/annotations/types/main.js';
3
5
  import { createAutoPromote } from '../first-party/auto-promote/factory.js';
4
6
  import { EXTENSION_ID as EXTENSION_ID_AUTO_PROMOTE } from '../first-party/auto-promote/types.js';
5
7
  import { createBoardEvents } from '../first-party/board-events/factory.js';
@@ -25,7 +27,8 @@ export const builtInExtensionFactoryMap = {
25
27
  [EXTENSION_ID_LEGAL_MOVES]: createLegalMoves,
26
28
  [EXTENSION_ID_BOARD_EVENTS]: createBoardEvents,
27
29
  [EXTENSION_ID_AUTO_PROMOTE]: createAutoPromote,
28
- [EXTENSION_ID_PROMOTION]: createPromotion
30
+ [EXTENSION_ID_PROMOTION]: createPromotion,
31
+ [EXTENSION_ID_ANNOTATIONS]: createAnnotations
29
32
  };
30
33
  export const DefaultBuiltinChessboardExtensions = [
31
34
  EXTENSION_ID_RENDERER,
@@ -36,5 +39,6 @@ export const DefaultBuiltinChessboardExtensions = [
36
39
  EXTENSION_ID_LEGAL_MOVES,
37
40
  EXTENSION_ID_BOARD_EVENTS,
38
41
  EXTENSION_ID_AUTO_PROMOTE,
39
- EXTENSION_ID_PROMOTION
42
+ EXTENSION_ID_PROMOTION,
43
+ EXTENSION_ID_ANNOTATIONS
40
44
  ];
@@ -1,21 +1,17 @@
1
- import { isUpdateContextCommonMounted } from './types/context/update.js';
2
1
  export function extensionSystemUpdateState(state, request) {
3
2
  // Prepare base context
4
- const contextCommon = {
3
+ const contextCommonPart = {
5
4
  previousFrame: state.currentFrame,
6
5
  mutation: request.mutation,
7
6
  currentFrame: request.state
8
7
  };
9
8
  // Update invalidation state based on the new request
10
9
  for (const extension of state.extensions.values()) {
11
- const context = isUpdateContextCommonMounted(contextCommon)
12
- ? {
13
- ...contextCommon,
14
- invalidation: extension.invalidation
15
- }
16
- : {
17
- ...contextCommon
18
- };
10
+ const contextCommon = {
11
+ ...contextCommonPart,
12
+ invalidation: extension.invalidation
13
+ };
14
+ const context = contextCommon;
19
15
  extension.instance.onUpdate?.(context);
20
16
  }
21
17
  state.currentFrame = request.state;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export type { MoveOutput } from './extensions/build/index.js';
2
1
  export type { ColorInput, MoveRequestInput, PiecePositionRecordString, PositionInput } from './state/board/types/input.js';
2
+ export type { MoveOutput } from './state/board/types/output.js';
3
3
  export type { MovabilityInput, MoveDestinationInput } from './state/interaction/types/input.js';
4
4
  export { createBoard } from './wrapper/factory.js';
5
5
  export type { Chessboard, ChessboardExtensionInput, ChessboardInitOptions } from './wrapper/types.js';
@@ -1,5 +1,5 @@
1
1
  import { validateIsMounted, validateIsNotMounted } from './rendering/helpers.js';
2
- import { clearElementChildren } from './svg/helpers.js';
2
+ import { clearSvgElementChildren } from './svg/helpers.js';
3
3
  export function renderMount(state, element) {
4
4
  validateIsNotMounted(state);
5
5
  state.container = element;
@@ -16,8 +16,8 @@ export function renderUnmount(state) {
16
16
  for (const extensionRec of state.extensions.values()) {
17
17
  extensionRec.extension.instance.unmount?.();
18
18
  // clear the slot roots
19
- for (const slotRoot of Object.values(extensionRec.render.slots)) {
20
- clearElementChildren(slotRoot);
19
+ for (const [, slotRoot] of Object.entries(extensionRec.render.slots)) {
20
+ clearSvgElementChildren(slotRoot);
21
21
  }
22
22
  }
23
23
  // remove our svg root from the container
@@ -1,5 +1,5 @@
1
1
  import { sceneSizesEqual } from '../../layout/geometry/helpers.js';
2
- import { updateElementAttributes } from '../svg/helpers.js';
2
+ import { updateSvgElementAttributes } from '../svg/helpers.js';
3
3
  import { validateIsMounted } from './helpers.js';
4
4
  export function checkNeedsRender(state) {
5
5
  for (const extensionRec of state.extensions.values()) {
@@ -20,7 +20,7 @@ export function performRenderPass(state, request) {
20
20
  const currentSize = request.layout.geometry.sceneSize;
21
21
  const prevSize = state.currentFrame?.layout.geometry?.sceneSize ?? null;
22
22
  if (!sceneSizesEqual(currentSize, prevSize)) {
23
- updateElementAttributes(state.svgRoots.svgRoot, {
23
+ updateSvgElementAttributes(state.svgRoots.svgRoot, {
24
24
  width: currentSize.width.toString(),
25
25
  height: currentSize.height.toString(),
26
26
  viewBox: `0 0 ${currentSize.width} ${currentSize.height}`
@@ -1,43 +1,58 @@
1
- import { createSvgElement } from './helpers.js';
1
+ import { createSvgDefsElement, createSvgElement, createSvgRootElement } from './helpers.js';
2
2
  export function createSvgRoots(options) {
3
- const { doc } = options;
4
- const svgRoot = createSvgElement(doc, 'svg', { 'data-chessboard-id': 'svg-root' });
3
+ const { element } = options;
4
+ const svgRoot = createSvgRootElement(element, { 'data-chessboard-id': 'svg-root' });
5
5
  svgRoot.style.setProperty('user-select', 'none');
6
6
  svgRoot.style.setProperty('-webkit-user-select', 'none');
7
7
  svgRoot.style.setProperty('touch-action', 'pinch-zoom');
8
8
  svgRoot.style.setProperty('-webkit-touch-callout', 'none');
9
9
  svgRoot.style.setProperty('-webkit-tap-highlight-color', 'transparent');
10
+ // Create children in the correct order
11
+ const board = createSvgElement(svgRoot, 'g', { 'data-chessboard-id': 'board-root' });
12
+ const coordinates = createSvgElement(svgRoot, 'g', {
13
+ 'data-chessboard-id': 'coordinates-root'
14
+ });
15
+ const underPieces = createSvgElement(svgRoot, 'g', {
16
+ 'data-chessboard-id': 'under-pieces-root'
17
+ });
18
+ const pieces = createSvgElement(svgRoot, 'g', { 'data-chessboard-id': 'pieces-root' });
19
+ const overPieces = createSvgElement(svgRoot, 'g', {
20
+ 'data-chessboard-id': 'over-pieces-root'
21
+ });
22
+ const animation = createSvgElement(svgRoot, 'g', {
23
+ 'data-chessboard-id': 'animation-root'
24
+ });
25
+ const underDrag = createSvgElement(svgRoot, 'g', {
26
+ 'data-chessboard-id': 'under-drag-root'
27
+ });
28
+ const drag = createSvgElement(svgRoot, 'g', { 'data-chessboard-id': 'drag-root' });
29
+ const overDrag = createSvgElement(svgRoot, 'g', {
30
+ 'data-chessboard-id': 'over-drag-root'
31
+ });
10
32
  const result = {
11
33
  svgRoot,
12
- defs: createSvgElement(doc, 'defs', { 'data-chessboard-id': 'defs-root' }),
13
- board: createSvgElement(doc, 'g', { 'data-chessboard-id': 'board-root' }),
14
- coordinates: createSvgElement(doc, 'g', { 'data-chessboard-id': 'coordinates-root' }),
15
- underPieces: createSvgElement(doc, 'g', { 'data-chessboard-id': 'under-pieces-root' }),
16
- pieces: createSvgElement(doc, 'g', { 'data-chessboard-id': 'pieces-root' }),
17
- overPieces: createSvgElement(doc, 'g', { 'data-chessboard-id': 'over-pieces-root' }),
18
- animation: createSvgElement(doc, 'g', { 'data-chessboard-id': 'animation-root' }),
19
- underDrag: createSvgElement(doc, 'g', { 'data-chessboard-id': 'under-drag-root' }),
20
- drag: createSvgElement(doc, 'g', { 'data-chessboard-id': 'drag-root' }),
21
- overDrag: createSvgElement(doc, 'g', { 'data-chessboard-id': 'over-drag-root' })
34
+ board,
35
+ coordinates,
36
+ underPieces,
37
+ pieces,
38
+ overPieces,
39
+ animation,
40
+ underDrag,
41
+ drag,
42
+ overDrag
22
43
  };
23
- // Attach layers in the correct order
24
- svgRoot.appendChild(result.defs);
25
- svgRoot.appendChild(result.board);
26
- svgRoot.appendChild(result.coordinates);
27
- svgRoot.appendChild(result.underPieces);
28
- svgRoot.appendChild(result.pieces);
29
- svgRoot.appendChild(result.overPieces);
30
- svgRoot.appendChild(result.animation);
31
- svgRoot.appendChild(result.underDrag);
32
- svgRoot.appendChild(result.drag);
33
- svgRoot.appendChild(result.overDrag);
34
44
  return result;
35
45
  }
36
46
  export function allocateExtensionSlotRoots(svgRoots, extensionId, slots) {
37
47
  const result = {};
38
48
  for (const slot of slots) {
39
49
  const id = `extension-slot-root-${slot}-${extensionId}`;
40
- result[slot] = createSvgElement(svgRoots[slot], 'g', { 'data-chessboard-id': id });
50
+ if (slot === 'defs') {
51
+ result[slot] = createSvgDefsElement(svgRoots.svgRoot, { 'data-chessboard-id': id });
52
+ }
53
+ else {
54
+ result[slot] = createSvgElement(svgRoots[slot], 'g', { 'data-chessboard-id': id });
55
+ }
41
56
  }
42
57
  return result;
43
58
  }
@@ -9,10 +9,14 @@ export declare const SVG_NS = "http://www.w3.org/2000/svg";
9
9
  export declare function isLightSquare(sq: Square): boolean;
10
10
  export type SvgElementNames = keyof SVGElementTagNameMap;
11
11
  export type SvgElementAttributes = Record<string, string>;
12
- export type SvgElementOtherAttributes = SvgElementAttributes;
13
12
  export type SvgElementWithIdAttributes = SvgElementAttributes & {
14
13
  'data-chessboard-id': string;
15
14
  };
16
- export declare function createSvgElement<K extends SvgElementNames>(parentOrDoc: Element | Document, name: K, attrs: SvgElementWithIdAttributes): SVGElementTagNameMap[K];
17
- export declare function updateElementAttributes(element: Element, attrs: SvgElementOtherAttributes): void;
18
- export declare function clearElementChildren(element: Element): void;
15
+ export type SvgElementOtherAttributes = SvgElementAttributes & {
16
+ 'data-chessboard-id'?: never;
17
+ };
18
+ export declare function createSvgRootElement(parent: HTMLElement, attrs: SvgElementWithIdAttributes): SVGSVGElement;
19
+ export declare function createSvgDefsElement(parent: SVGSVGElement, attrs: SvgElementWithIdAttributes): SVGDefsElement;
20
+ export declare function createSvgElement<K extends Exclude<SvgElementNames, 'svg' | 'defs'>>(parent: SVGElement, name: K, attrs: SvgElementWithIdAttributes): SVGElementTagNameMap[K];
21
+ export declare function updateSvgElementAttributes(element: SVGElement, attrs: SvgElementOtherAttributes): void;
22
+ export declare function clearSvgElementChildren(element: SVGElement): void;
@@ -11,23 +11,38 @@ export function isLightSquare(sq) {
11
11
  const r = rankOf(sq);
12
12
  return ((f + r) & 1) === 1;
13
13
  }
14
- export function createSvgElement(parentOrDoc, name, attrs) {
15
- const doc = parentOrDoc instanceof Document ? parentOrDoc : parentOrDoc.ownerDocument;
16
- const el = doc.createElementNS(SVG_NS, name);
14
+ function _updateElementAttributes(element, attrs) {
17
15
  for (const [key, value] of Object.entries(attrs)) {
18
- el.setAttribute(key, value);
19
- }
20
- if (parentOrDoc instanceof Element) {
21
- parentOrDoc.appendChild(el);
16
+ element.setAttribute(key, value);
22
17
  }
18
+ }
19
+ export function createSvgRootElement(parent, attrs) {
20
+ const doc = parent.ownerDocument;
21
+ const el = doc.createElementNS(SVG_NS, 'svg');
22
+ _updateElementAttributes(el, attrs);
23
+ parent.appendChild(el);
23
24
  return el;
24
25
  }
25
- export function updateElementAttributes(element, attrs) {
26
- for (const [key, value] of Object.entries(attrs)) {
27
- element.setAttribute(key, value);
28
- }
26
+ export function createSvgDefsElement(parent, attrs) {
27
+ const doc = parent.ownerDocument;
28
+ const el = doc.createElementNS(SVG_NS, 'defs');
29
+ _updateElementAttributes(el, attrs);
30
+ // Keep extension-owned defs roots before visual roots.
31
+ const firstNonDefsChild = Array.from(parent.children).find((child) => child.tagName.toLowerCase() !== 'defs');
32
+ parent.insertBefore(el, firstNonDefsChild ?? null);
33
+ return el;
34
+ }
35
+ export function createSvgElement(parent, name, attrs) {
36
+ const doc = parent.ownerDocument;
37
+ const el = doc.createElementNS(SVG_NS, name);
38
+ _updateElementAttributes(el, attrs);
39
+ parent.appendChild(el);
40
+ return el;
41
+ }
42
+ export function updateSvgElementAttributes(element, attrs) {
43
+ _updateElementAttributes(element, attrs);
29
44
  }
30
- export function clearElementChildren(element) {
45
+ export function clearSvgElementChildren(element) {
31
46
  while (element.firstChild) {
32
47
  element.removeChild(element.firstChild);
33
48
  }
@@ -0,0 +1,6 @@
1
+ export interface SvgIdResolver {
2
+ readonly prefix: string;
3
+ makeId(scope: string, localId: string): string;
4
+ makeHref(scope: string, localId: string): string;
5
+ }
6
+ export declare function createSvgIdResolver(): SvgIdResolver;
@@ -0,0 +1,11 @@
1
+ let nextId = 0;
2
+ export function createSvgIdResolver() {
3
+ const prefix = `cb${nextId++}`;
4
+ function makeId(scope, localId) {
5
+ return `${prefix}-${scope}-${localId}`;
6
+ }
7
+ function makeHref(scope, localId) {
8
+ return `#${makeId(scope, localId)}`;
9
+ }
10
+ return { prefix, makeId, makeHref };
11
+ }
@@ -3,9 +3,10 @@ import { RenderFrameSnapshot } from '../extensions/types/basic/render.js';
3
3
  import { TransientInput } from '../extensions/types/basic/transient-visuals.js';
4
4
  import { ExtensionSystemExtensionRecord, ExtensionSystemSharedDataForRenderSystem } from '../extensions/types/main.js';
5
5
  import { Scheduler } from './scheduler/types.js';
6
- export interface SvgRoots extends ExtensionSlotSvgRoots<typeof ALL_EXTENSION_SLOTS> {
6
+ export type RootExtensionSlotName = Exclude<(typeof ALL_EXTENSION_SLOTS)[number], 'defs'>;
7
+ export declare const ROOT_EXTENSION_SLOTS: readonly RootExtensionSlotName[];
8
+ export interface SvgRoots extends ExtensionSlotSvgRoots<typeof ROOT_EXTENSION_SLOTS> {
7
9
  readonly svgRoot: SVGSVGElement;
8
- readonly defs: SVGDefsElement;
9
10
  }
10
11
  export interface RenderExtensionRecordRender {
11
12
  readonly slots: ExtensionAllocatedSlotsInternal;
@@ -24,7 +25,7 @@ export interface RenderSystemInternal {
24
25
  readonly transientVisualsSubscribers: ReadonlySet<string>;
25
26
  }
26
27
  export interface RenderSystemInitOptions {
27
- doc: Document;
28
+ element: HTMLElement;
28
29
  sharedDataFromExtensionSystem: ExtensionSystemSharedDataForRenderSystem;
29
30
  }
30
31
  export interface RenderSystemInitOptionsInternal extends RenderSystemInitOptions {
@@ -1 +1,2 @@
1
- export {};
1
+ import { ALL_EXTENSION_SLOTS } from '../extensions/types/basic/mount.js';
2
+ export const ROOT_EXTENSION_SLOTS = ALL_EXTENSION_SLOTS.filter((slot) => slot !== 'defs');
@@ -1,3 +1,5 @@
1
+ import { DragSessionSnapshot } from '../../state/interaction/types/internal.js';
1
2
  import { RuntimeInteractionSurface } from '../input/controller/types.js';
2
- import { GetInternalState } from '../types/main.js';
3
+ import { GetInternalState, RuntimeInternal } from '../types/main.js';
4
+ export declare function notifyExtensionCancelDragIfOwned(internalState: RuntimeInternal, dragSession: DragSessionSnapshot | null): void;
3
5
  export declare function createRuntimeInteractionSurface(state: GetInternalState): RuntimeInteractionSurface;
@@ -3,6 +3,11 @@ import { isEmptyPieceCode } from '../../state/board/check.js';
3
3
  import { isDragSessionCoreOwned } from '../../state/interaction/helpers.js';
4
4
  import { runtimeRunMutationPipeline } from '../mutation/run.js';
5
5
  import { uiMoveCompleteTo } from './helpers.js';
6
+ export function notifyExtensionCancelDragIfOwned(internalState, dragSession) {
7
+ if (dragSession && !isDragSessionCoreOwned(dragSession)) {
8
+ internalState.extensionSystem.cancelDrag(dragSession);
9
+ }
10
+ }
6
11
  export function createRuntimeInteractionSurface(state) {
7
12
  return {
8
13
  getInteractionStateSnapshot() {
@@ -80,13 +85,17 @@ export function createRuntimeInteractionSurface(state) {
80
85
  cancelActiveInteraction() {
81
86
  const internalState = state();
82
87
  const mutationSession = internalState.mutation.getSession();
83
- internalState.state.interaction.clearActive(mutationSession);
88
+ const interaction = internalState.state.interaction;
89
+ notifyExtensionCancelDragIfOwned(internalState, interaction.dragSession);
90
+ interaction.clearActive(mutationSession);
84
91
  runtimeRunMutationPipeline(internalState);
85
92
  },
86
93
  cancelInteraction() {
87
94
  const internalState = state();
88
95
  const mutationSession = internalState.mutation.getSession();
89
- internalState.state.interaction.clear(mutationSession);
96
+ const interaction = internalState.state.interaction;
97
+ notifyExtensionCancelDragIfOwned(internalState, interaction.dragSession);
98
+ interaction.clear(mutationSession);
90
99
  runtimeRunMutationPipeline(internalState);
91
100
  },
92
101
  updateDragSessionCurrentTarget(target) {
@@ -1,6 +1,6 @@
1
1
  import assert from '@ktarmyshov/assert';
2
2
  import { createExtensionSystem } from '../../extensions/factory/main.js';
3
- import { assertFrameRenderable } from '../../extensions/types/basic/update.js';
3
+ import { isFrameRenderable } from '../../extensions/types/basic/update.js';
4
4
  import { createLayout } from '../../layout/factory.js';
5
5
  import { createRenderSystem } from '../../render/factory.js';
6
6
  import { isNonEmptyPieceCode } from '../../state/board/check.js';
@@ -11,11 +11,11 @@ import { runtimeDestroy, runtimeMount, runtimeUnmount } from '../lifecycle.js';
11
11
  import { createRuntimeMutationPipeline } from '../mutation/factory.js';
12
12
  import { runtimeRunMutationPipeline } from '../mutation/run.js';
13
13
  import { createExtensionRuntimeSurfaceEvents } from './events.js';
14
- import { createRuntimeInteractionSurface } from './input.js';
14
+ import { createRuntimeInteractionSurface, notifyExtensionCancelDragIfOwned } from './input.js';
15
15
  function createRuntimeInternal(options) {
16
16
  const extensionSystem = createExtensionSystem(options);
17
17
  const render = createRenderSystem({
18
- doc: options.doc,
18
+ element: options.element,
19
19
  sharedDataFromExtensionSystem: extensionSystem.getSharedDataForRenderSystem()
20
20
  });
21
21
  return {
@@ -69,9 +69,13 @@ function createExtensionRuntimeSurfaceCommandsInternalSurface(getInternalState)
69
69
  state: state.state.getSnapshot(),
70
70
  layout: state.layout.getSnapshot()
71
71
  };
72
- assertFrameRenderable(renderRequest);
72
+ if (!isFrameRenderable(renderRequest)) {
73
+ return false;
74
+ }
73
75
  state.renderSystem.requestRender(renderRequest);
76
+ return true;
74
77
  }
78
+ return false;
75
79
  },
76
80
  setOrientation(orientation) {
77
81
  const state = getInternalState();
@@ -114,6 +118,7 @@ function createExtensionRuntimeSurfaceCommandsInternalSurface(getInternalState)
114
118
  clearActiveInteraction() {
115
119
  const state = getInternalState();
116
120
  const mutationSession = state.mutation.getSession();
121
+ notifyExtensionCancelDragIfOwned(state, state.state.interaction.dragSession);
117
122
  const changed = state.state.interaction.clearActive(mutationSession);
118
123
  runtimeRunMutationPipeline(state);
119
124
  return changed;
@@ -121,6 +126,7 @@ function createExtensionRuntimeSurfaceCommandsInternalSurface(getInternalState)
121
126
  clearInteraction() {
122
127
  const state = getInternalState();
123
128
  const mutationSession = state.mutation.getSession();
129
+ notifyExtensionCancelDragIfOwned(state, state.state.interaction.dragSession);
124
130
  const changed = state.state.interaction.clear(mutationSession);
125
131
  runtimeRunMutationPipeline(state);
126
132
  return changed;
@@ -1,11 +1,11 @@
1
1
  import { ALL_SCENE_POINTER_EVENT_TYPES } from '../../../extensions/types/basic/events.js';
2
2
  import { pointerEventDestroy, pointerEventHandler } from './pointer.js';
3
3
  export function eventHandler(state, e) {
4
- let context = null;
4
+ let context;
5
5
  if (ALL_SCENE_POINTER_EVENT_TYPES.has(e.type)) {
6
6
  context = pointerEventHandler(state, e);
7
7
  }
8
- if (!context) {
8
+ else {
9
9
  context = {
10
10
  rawEvent: e,
11
11
  sceneEvent: null