@mirasen/chessboard 1.1.5 → 1.2.1

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 +45 -0
  2. package/README.md +61 -13
  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 -2
@@ -1,3 +1,3 @@
1
1
  import { ExtensionRenderContext } from '../../../types/context/render.js';
2
2
  import { MainRendererPiecesInternal } from './types.js';
3
- export declare function rendererPiecesRender(state: MainRendererPiecesInternal, context: ExtensionRenderContext, layer: SVGElement): void;
3
+ export declare function rendererPiecesRender(state: MainRendererPiecesInternal, context: ExtensionRenderContext, slot: SVGGElement): void;
@@ -1,8 +1,8 @@
1
- import { createSvgElement, updateElementAttributes } from '../../../../render/svg/helpers.js';
1
+ import { createSvgElement, updateSvgElementAttributes } from '../../../../render/svg/helpers.js';
2
2
  import { isNonEmptyPieceCode } from '../../../../state/board/check.js';
3
3
  import { SQUARE_COUNT } from '../../../../state/board/types/internal.js';
4
4
  import { DirtyLayer } from '../types/extension.js';
5
- export function rendererPiecesRender(state, context, layer) {
5
+ export function rendererPiecesRender(state, context, slot) {
6
6
  if ((context.invalidation.dirtyLayers & DirtyLayer.Pieces) === 0) {
7
7
  return;
8
8
  }
@@ -13,22 +13,22 @@ export function rendererPiecesRender(state, context, layer) {
13
13
  const existing = state.pieceNodes.get(sq) || null;
14
14
  const suppressed = state.suppressedSquares.has(sq);
15
15
  if (isNonEmptyPieceCode(pieceCode) && !suppressed) {
16
- const url = state.config[pieceCode];
16
+ const href = state.resolver.getHref(pieceCode);
17
17
  const r = geometry.getSquareRect(sq);
18
18
  if (existing !== null) {
19
- updateElementAttributes(existing.root, {
19
+ updateSvgElementAttributes(existing.root, {
20
20
  x: r.x.toString(),
21
21
  y: r.y.toString(),
22
22
  width: r.width.toString(),
23
23
  height: r.height.toString(),
24
- href: url
24
+ href
25
25
  });
26
26
  }
27
27
  else {
28
28
  state.pieceNodes.set(sq, {
29
- root: createSvgElement(layer, 'image', {
29
+ root: createSvgElement(slot, 'use', {
30
30
  'data-chessboard-id': `piece-${pieceCode}-${sq}`,
31
- href: url,
31
+ href,
32
32
  x: r.x.toString(),
33
33
  y: r.y.toString(),
34
34
  width: r.width.toString(),
@@ -38,7 +38,7 @@ export function rendererPiecesRender(state, context, layer) {
38
38
  }
39
39
  }
40
40
  else if (existing !== null) {
41
- layer.removeChild(existing.root);
41
+ slot.removeChild(existing.root);
42
42
  state.pieceNodes.delete(sq);
43
43
  }
44
44
  }
@@ -2,19 +2,19 @@ import { Square } from '../../../../state/board/types/internal.js';
2
2
  import { ExtensionCleanAnimationContext } from '../../../types/context/animation.js';
3
3
  import { ExtensionRenderContext } from '../../../types/context/render.js';
4
4
  import { ExtensionUpdateContext } from '../../../types/context/update.js';
5
- import { PieceUrls } from '../types/internal.js';
5
+ import type { PieceSymbolResolver } from '../piece-symbols.js';
6
6
  type PieceNodeRecord = {
7
- root: SVGImageElement;
7
+ root: SVGUseElement;
8
8
  };
9
9
  export interface MainRendererPiecesInternal {
10
- readonly config: PieceUrls;
10
+ readonly resolver: PieceSymbolResolver;
11
11
  readonly pieceNodes: Map<Square, PieceNodeRecord>;
12
12
  suppressedSquares: ReadonlySet<Square>;
13
13
  }
14
14
  export interface MainRendererPieces {
15
15
  onUpdate(context: ExtensionUpdateContext, animationSuppressedSquares: ReadonlySet<Square>): void;
16
16
  refreshSuppressedSquares(context: ExtensionCleanAnimationContext, animationSuppressedSquares: ReadonlySet<Square>): void;
17
- render(context: ExtensionRenderContext, layer: SVGElement): void;
17
+ render(context: ExtensionRenderContext, slot: SVGGElement): void;
18
18
  unmount(): void;
19
19
  }
20
20
  export {};
@@ -1,7 +1,7 @@
1
1
  import { ExtensionDefinition, ExtensionInstance } from '../../../types/extension.js';
2
2
  import { MainRendererConfigInput } from './input.js';
3
3
  export type MainRendererInitOptions = Partial<MainRendererConfigInput>;
4
- export declare const EXTENSION_SLOTS: readonly ["board", "coordinates", "pieces", "animation", "drag"];
4
+ export declare const EXTENSION_SLOTS: readonly ["defs", "board", "coordinates", "pieces", "animation", "drag"];
5
5
  export type ExtensionSlotsType = typeof EXTENSION_SLOTS;
6
6
  export declare const EXTENSION_ID: "renderer";
7
7
  export type MainRendererDefinition = ExtensionDefinition<typeof EXTENSION_ID, typeof EXTENSION_SLOTS, never>;
@@ -1,4 +1,11 @@
1
- export const EXTENSION_SLOTS = ['board', 'coordinates', 'pieces', 'animation', 'drag'];
1
+ export const EXTENSION_SLOTS = [
2
+ 'defs',
3
+ 'board',
4
+ 'coordinates',
5
+ 'pieces',
6
+ 'animation',
7
+ 'drag'
8
+ ];
2
9
  export const EXTENSION_ID = 'renderer';
3
10
  export var DirtyLayer;
4
11
  (function (DirtyLayer) {
@@ -4,6 +4,7 @@ import { MainRendererAnimation } from '../animation/types.js';
4
4
  import { MainRendererBoard } from '../board/types.js';
5
5
  import { MainRendererCoordinates } from '../coordinates/types.js';
6
6
  import { MainRendererDrag } from '../drag/types.js';
7
+ import type { PieceSymbolResolver } from '../piece-symbols.js';
7
8
  import { MainRendererPieces } from '../pieces/types.js';
8
9
  import { ExtensionSlotsType } from './extension.js';
9
10
  export interface MainRendererInstanceInternal extends ExtensionInternalBase<ExtensionSlotsType> {
@@ -13,4 +14,5 @@ export interface MainRendererInstanceInternal extends ExtensionInternalBase<Exte
13
14
  readonly drag: MainRendererDrag;
14
15
  readonly animation: MainRendererAnimation;
15
16
  readonly runtimeSurface: ExtensionRuntimeSurface;
17
+ readonly pieceSymbolResolver: PieceSymbolResolver;
16
18
  }
@@ -1,5 +1,5 @@
1
1
  import assert from '@ktarmyshov/assert';
2
- import { createSvgElement, updateElementAttributes } from '../../../render/svg/helpers.js';
2
+ import { createSvgElement, updateSvgElementAttributes } from '../../../render/svg/helpers.js';
3
3
  import { fileOf, rankOf, squareOf } from '../../../state/board/coords.js';
4
4
  import { toPieceCode } from '../../../state/board/piece.js';
5
5
  import { isUpdateContextRenderable } from '../../types/context/update.js';
@@ -18,7 +18,7 @@ export function createPromotion(config = {}) {
18
18
  }
19
19
  function createPromotionInternal(options, config) {
20
20
  return {
21
- ...extensionCreateInternalBase(),
21
+ ...extensionCreateInternalBase(options),
22
22
  svgPromotionPieces: new Map(),
23
23
  activePromotionSquares: new Map(),
24
24
  svgHoverRect: null,
@@ -117,7 +117,7 @@ function createPromotionInstance(options, config) {
117
117
  }
118
118
  // Create or update a node for each promotion role
119
119
  assert(internalState.slotRoots, 'Slot roots should be available when render is called');
120
- const layer = internalState.slotRoots.animation;
120
+ const slot = internalState.slotRoots.animation;
121
121
  for (let i = 0; i < promotedToSorted.length; i++) {
122
122
  const roleCode = promotedToSorted[i];
123
123
  const displayRank = (targetRank + i * rankStep);
@@ -144,15 +144,15 @@ function createPromotionInstance(options, config) {
144
144
  internalState.activePromotionSquares.set(displaySquare, roleCode);
145
145
  const existing = internalState.svgPromotionPieces.get(roleCode) ?? null;
146
146
  if (existing !== null) {
147
- updateElementAttributes(existing.rect, rectAttrs);
148
- updateElementAttributes(existing.svg, imageAttrs);
147
+ updateSvgElementAttributes(existing.rect, rectAttrs);
148
+ updateSvgElementAttributes(existing.svg, imageAttrs);
149
149
  }
150
150
  else {
151
- const rect = createSvgElement(layer, 'rect', {
151
+ const rect = createSvgElement(slot, 'rect', {
152
152
  'data-chessboard-id': `promotion-bg-${roleCode}`,
153
153
  ...rectAttrs
154
154
  });
155
- const svg = createSvgElement(layer, 'image', {
155
+ const svg = createSvgElement(slot, 'image', {
156
156
  'data-chessboard-id': `promotion-piece-${roleCode}`,
157
157
  ...imageAttrs
158
158
  });
@@ -176,12 +176,12 @@ function createPromotionInstance(options, config) {
176
176
  'shape-rendering': 'crispEdges'
177
177
  };
178
178
  if (internalState.svgHoverRect) {
179
- updateElementAttributes(internalState.svgHoverRect, attrs);
179
+ updateSvgElementAttributes(internalState.svgHoverRect, attrs);
180
180
  }
181
181
  else {
182
182
  assert(internalState.slotRoots, 'Slot roots should be available when renderTransientVisuals is called');
183
- const layer = internalState.slotRoots.animation;
184
- internalState.svgHoverRect = createSvgElement(layer, 'rect', {
183
+ const slot = internalState.slotRoots.animation;
184
+ internalState.svgHoverRect = createSvgElement(slot, 'rect', {
185
185
  'data-chessboard-id': 'promotion-hover',
186
186
  ...attrs
187
187
  });
@@ -1,6 +1,6 @@
1
1
  import assert from '@ktarmyshov/assert';
2
2
  import { toMerged } from 'es-toolkit';
3
- import { createSvgElement, updateElementAttributes } from '../../../render/svg/helpers.js';
3
+ import { createSvgElement, updateSvgElementAttributes } from '../../../render/svg/helpers.js';
4
4
  import { isUpdateContextRenderable } from '../../types/context/update.js';
5
5
  import { extensionCreateInternalBase, extensionDestroyBase, extensionMountBase, extensionUnmountBase } from '../common/helpers.js';
6
6
  import { DEFAULT_CONFIG, EXTENSION_ID, EXTENSION_SLOTS } from './types.js';
@@ -9,14 +9,14 @@ export function createSelectedSquare(config = {}) {
9
9
  return {
10
10
  id: EXTENSION_ID,
11
11
  slots: EXTENSION_SLOTS,
12
- createInstance() {
13
- return createSelectedSquareInstance(mergedConfig);
12
+ createInstance(options) {
13
+ return createSelectedSquareInstance(options, mergedConfig);
14
14
  }
15
15
  };
16
16
  }
17
- function createSelectedSquareInternal(config) {
17
+ function createSelectedSquareInternal(options, config) {
18
18
  return {
19
- ...extensionCreateInternalBase(),
19
+ ...extensionCreateInternalBase(options),
20
20
  svgRect: null,
21
21
  config
22
22
  };
@@ -24,8 +24,8 @@ function createSelectedSquareInternal(config) {
24
24
  function extensionClean(state) {
25
25
  state.svgRect = null;
26
26
  }
27
- function createSelectedSquareInstance(config) {
28
- const internalState = createSelectedSquareInternal(config);
27
+ function createSelectedSquareInstance(options, config) {
28
+ const internalState = createSelectedSquareInternal(options, config);
29
29
  return {
30
30
  id: EXTENSION_ID,
31
31
  mount(env) {
@@ -73,7 +73,7 @@ function createSelectedSquareInstance(config) {
73
73
  });
74
74
  }
75
75
  else {
76
- updateElementAttributes(internalState.svgRect, rectAttributes);
76
+ updateSvgElementAttributes(internalState.svgRect, rectAttributes);
77
77
  }
78
78
  },
79
79
  unmount() {
@@ -1,5 +1,5 @@
1
1
  import assert from '@ktarmyshov/assert';
2
- import { createSvgElement, updateElementAttributes } from '../../../render/svg/helpers.js';
2
+ import { createSvgElement, updateSvgElementAttributes } from '../../../render/svg/helpers.js';
3
3
  import { isUpdateContextRenderable } from '../../types/context/update.js';
4
4
  import { extensionCreateInternalBase, extensionDestroyBase, extensionMountBase, extensionUnmountBase } from '../common/helpers.js';
5
5
  import { EXTENSION_ID, EXTENSION_SLOTS } from './types.js';
@@ -7,14 +7,14 @@ export function createWatermark() {
7
7
  return {
8
8
  id: EXTENSION_ID,
9
9
  slots: EXTENSION_SLOTS,
10
- createInstance() {
11
- return createWatermarkInstance();
10
+ createInstance(options) {
11
+ return createWatermarkInstance(options);
12
12
  }
13
13
  };
14
14
  }
15
- function createWatermarkInternal() {
15
+ function createWatermarkInternal(options) {
16
16
  return {
17
- ...extensionCreateInternalBase(),
17
+ ...extensionCreateInternalBase(options),
18
18
  svgWatermark: null
19
19
  };
20
20
  }
@@ -24,8 +24,8 @@ function extensionClean(state) {
24
24
  const watermarkUrl = new URL('../../../../assets/watermark/mirasen.svg', import.meta.url).toString();
25
25
  const squareRatio = 0.8; // watermark size relative to square size
26
26
  const opacity = '0.3';
27
- function createWatermarkInstance() {
28
- const internalState = createWatermarkInternal();
27
+ function createWatermarkInstance(options) {
28
+ const internalState = createWatermarkInternal(options);
29
29
  return {
30
30
  id: EXTENSION_ID,
31
31
  mount(env) {
@@ -67,7 +67,7 @@ function createWatermarkInstance() {
67
67
  });
68
68
  }
69
69
  else {
70
- updateElementAttributes(internalState.svgWatermark, watermarkAttributes);
70
+ updateSvgElementAttributes(internalState.svgWatermark, watermarkAttributes);
71
71
  }
72
72
  },
73
73
  unmount() {
@@ -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}`