@flowgram-vue/core 0.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 (133) hide show
  1. package/LICENSE +22 -0
  2. package/dist/index.cjs +0 -0
  3. package/dist/index.cjs.map +1 -0
  4. package/dist/index.d.ts +1 -0
  5. package/dist/index.js +0 -0
  6. package/dist/index.js.map +1 -0
  7. package/package.json +63 -0
  8. package/src/common/config-entity.ts +80 -0
  9. package/src/common/entity-data.ts +171 -0
  10. package/src/common/entity-manager-contribution.ts +12 -0
  11. package/src/common/entity-manager.ts +475 -0
  12. package/src/common/entity.ts +482 -0
  13. package/src/common/index.ts +22 -0
  14. package/src/common/playground-context.ts +35 -0
  15. package/src/common/playground-decorator-helper.ts +113 -0
  16. package/src/common/playground-decorators.ts +85 -0
  17. package/src/common/playground-schedule.ts +30 -0
  18. package/src/common/protect-wheel-area.ts +11 -0
  19. package/src/common/schema/index.ts +14 -0
  20. package/src/common/schema/node.ts +15 -0
  21. package/src/common/schema/opacity-schema.ts +19 -0
  22. package/src/common/schema/origin-schema.ts +35 -0
  23. package/src/common/schema/position-schema.ts +35 -0
  24. package/src/common/schema/rotation-schema.ts +19 -0
  25. package/src/common/schema/scale-schema.ts +35 -0
  26. package/src/common/schema/size-schema.ts +42 -0
  27. package/src/common/schema/skew-schema.ts +35 -0
  28. package/src/common/schema/transform-schema.ts +613 -0
  29. package/src/common/utils/bounds.spec.ts +229 -0
  30. package/src/common/utils/bounds.ts +176 -0
  31. package/src/common/utils/index.ts +6 -0
  32. package/src/composables/index.ts +16 -0
  33. package/src/composables/use-config-entity.ts +31 -0
  34. package/src/composables/use-entities.ts +26 -0
  35. package/src/composables/use-entity-data-from-context.ts +34 -0
  36. package/src/composables/use-entity-from-context.ts +31 -0
  37. package/src/composables/use-listen-events.ts +22 -0
  38. package/src/composables/use-playground-container.ts +16 -0
  39. package/src/composables/use-playground-context.ts +15 -0
  40. package/src/composables/use-playground-drag.ts +31 -0
  41. package/src/composables/use-playground.ts +16 -0
  42. package/src/composables/use-refresh.ts +6 -0
  43. package/src/composables/use-service.ts +17 -0
  44. package/src/core/index.ts +8 -0
  45. package/src/core/layer/config/editor-state-config-entity.ts +180 -0
  46. package/src/core/layer/config/index.ts +7 -0
  47. package/src/core/layer/config/playground-config-entity.ts +604 -0
  48. package/src/core/layer/index.ts +8 -0
  49. package/src/core/layer/layer.ts +248 -0
  50. package/src/core/layer/playground-layer.ts +547 -0
  51. package/src/core/pipeline/index.ts +10 -0
  52. package/src/core/pipeline/pipeline-entities-selector.ts +200 -0
  53. package/src/core/pipeline/pipeline-entities.ts +230 -0
  54. package/src/core/pipeline/pipeline-registry.ts +344 -0
  55. package/src/core/pipeline/pipeline-renderer.ts +248 -0
  56. package/src/core/pipeline/pipeline-vue-utils.ts +96 -0
  57. package/src/core/pipeline/pipeline.ts +28 -0
  58. package/src/core/utils/index.ts +12 -0
  59. package/src/core/utils/inject-provider-decorators.ts +27 -0
  60. package/src/core/utils/lazy-inject-decorators.ts +38 -0
  61. package/src/core/utils/mouse-touch-event.ts +120 -0
  62. package/src/core/utils/playground-drag.ts +511 -0
  63. package/src/core/utils/playground-gesture.spec.ts +135 -0
  64. package/src/core/utils/playground-gesture.ts +118 -0
  65. package/src/core/utils/tween.ts +156 -0
  66. package/src/core/utils/use-gesture/core/Controller.ts +212 -0
  67. package/src/core/utils/use-gesture/core/EventStore.ts +46 -0
  68. package/src/core/utils/use-gesture/core/TimeoutStore.ts +28 -0
  69. package/src/core/utils/use-gesture/core/actions.ts +63 -0
  70. package/src/core/utils/use-gesture/core/config/commonConfigResolver.ts +86 -0
  71. package/src/core/utils/use-gesture/core/config/coordinatesConfigResolver.ts +48 -0
  72. package/src/core/utils/use-gesture/core/config/dragConfigResolver.ts +140 -0
  73. package/src/core/utils/use-gesture/core/config/hoverConfigResolver.ts +11 -0
  74. package/src/core/utils/use-gesture/core/config/moveConfigResolver.ts +11 -0
  75. package/src/core/utils/use-gesture/core/config/pinchConfigResolver.ts +59 -0
  76. package/src/core/utils/use-gesture/core/config/resolver.ts +70 -0
  77. package/src/core/utils/use-gesture/core/config/scrollConfigResolver.ts +8 -0
  78. package/src/core/utils/use-gesture/core/config/sharedConfigResolver.ts +28 -0
  79. package/src/core/utils/use-gesture/core/config/support.ts +52 -0
  80. package/src/core/utils/use-gesture/core/config/wheelConfigResolver.ts +8 -0
  81. package/src/core/utils/use-gesture/core/engines/CoordinatesEngine.ts +78 -0
  82. package/src/core/utils/use-gesture/core/engines/DragEngine.ts +403 -0
  83. package/src/core/utils/use-gesture/core/engines/Engine.ts +406 -0
  84. package/src/core/utils/use-gesture/core/engines/HoverEngine.ts +43 -0
  85. package/src/core/utils/use-gesture/core/engines/MoveEngine.ts +52 -0
  86. package/src/core/utils/use-gesture/core/engines/PinchEngine.ts +345 -0
  87. package/src/core/utils/use-gesture/core/engines/ScrollEngine.ts +42 -0
  88. package/src/core/utils/use-gesture/core/engines/WheelEngine.ts +48 -0
  89. package/src/core/utils/use-gesture/core/index.ts +7 -0
  90. package/src/core/utils/use-gesture/core/parser.ts +92 -0
  91. package/src/core/utils/use-gesture/core/types/action.ts +19 -0
  92. package/src/core/utils/use-gesture/core/types/config.ts +255 -0
  93. package/src/core/utils/use-gesture/core/types/handlers.ts +73 -0
  94. package/src/core/utils/use-gesture/core/types/index.ts +11 -0
  95. package/src/core/utils/use-gesture/core/types/internalConfig.ts +80 -0
  96. package/src/core/utils/use-gesture/core/types/state.ts +275 -0
  97. package/src/core/utils/use-gesture/core/types/utils.ts +204 -0
  98. package/src/core/utils/use-gesture/core/types.ts +8 -0
  99. package/src/core/utils/use-gesture/core/utils/events.ts +158 -0
  100. package/src/core/utils/use-gesture/core/utils/fn.ts +32 -0
  101. package/src/core/utils/use-gesture/core/utils/maths.ts +63 -0
  102. package/src/core/utils/use-gesture/core/utils/state.ts +24 -0
  103. package/src/core/utils/use-gesture/core/utils.ts +8 -0
  104. package/src/core/utils/use-gesture/index.ts +6 -0
  105. package/src/core/utils/use-gesture/vanilla/DragGesture.ts +27 -0
  106. package/src/core/utils/use-gesture/vanilla/Gesture.ts +45 -0
  107. package/src/core/utils/use-gesture/vanilla/HoverGesture.ts +27 -0
  108. package/src/core/utils/use-gesture/vanilla/MoveGesture.ts +27 -0
  109. package/src/core/utils/use-gesture/vanilla/PinchGesture.ts +27 -0
  110. package/src/core/utils/use-gesture/vanilla/Recognizer.ts +43 -0
  111. package/src/core/utils/use-gesture/vanilla/ScrollGesture.ts +27 -0
  112. package/src/core/utils/use-gesture/vanilla/WheelGesture.ts +27 -0
  113. package/src/core/utils/use-gesture/vanilla/createGesture.ts +18 -0
  114. package/src/core/utils/use-gesture/vanilla/index.ts +18 -0
  115. package/src/env.d.ts +10 -0
  116. package/src/index.ts +17 -0
  117. package/src/playground-config.ts +70 -0
  118. package/src/playground-container.ts +129 -0
  119. package/src/playground-contribution.ts +81 -0
  120. package/src/playground-mock-tools.ts +143 -0
  121. package/src/playground.ts +401 -0
  122. package/src/plugin/index.ts +6 -0
  123. package/src/plugin/plugin.ts +226 -0
  124. package/src/services/clipboard-service.ts +40 -0
  125. package/src/services/context-menu-service.ts +25 -0
  126. package/src/services/index.ts +10 -0
  127. package/src/services/logger-service.ts +49 -0
  128. package/src/services/selection-service.ts +54 -0
  129. package/src/services/storage-service.ts +65 -0
  130. package/src/vue/index.ts +8 -0
  131. package/src/vue/playground-vue-context.ts +22 -0
  132. package/src/vue/playground-vue-provider.ts +115 -0
  133. package/src/vue/playground-vue-renderer.vue +44 -0
@@ -0,0 +1,255 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import { Vector2, Target, PointerType, NonUndefined } from './utils';
7
+ import { State } from './state';
8
+
9
+ export type GestureKey = Exclude<keyof State, 'shared'>;
10
+ export type CoordinatesKey = Exclude<GestureKey, 'pinch'>;
11
+
12
+ export type GenericOptions = {
13
+ /**
14
+ * Lets you specify a dom node or ref you want to attach the gesture to.
15
+ */
16
+ target?: Target;
17
+ /**
18
+ * Lets you specify which window element the gesture should bind events to
19
+ * (only relevant for the drag gesture).
20
+ */
21
+ window?: EventTarget;
22
+ /**
23
+ * Lets you customize if you want events to be passive or captured.
24
+ */
25
+ eventOptions?: AddEventListenerOptions;
26
+ /**
27
+ * When set to false none of the handlers will be fired.
28
+ */
29
+ enabled?: boolean;
30
+ /**
31
+ * A function that you can use to transform movement and offset values. Useful
32
+ * to map your screen coordinates to custom space coordinates such as a
33
+ * canvas.
34
+ */
35
+ transform?: (v: Vector2) => Vector2;
36
+ };
37
+
38
+ export type GestureOptions<T extends GestureKey> = GenericOptions & {
39
+ /**
40
+ * Whether the gesture is enabled.
41
+ */
42
+ enabled?: boolean;
43
+ /**
44
+ * Lets you customize if you want events to be passive or captured.
45
+ */
46
+ eventOptions?: AddEventListenerOptions;
47
+ /**
48
+ * The position `offset` will start from.
49
+ */
50
+ from?: Vector2 | ((state: NonUndefined<State[T]>) => Vector2);
51
+ /**
52
+ * The handler will fire only when the gesture displacement is greater than
53
+ * the threshold.
54
+ */
55
+ threshold?: number | Vector2;
56
+ /**
57
+ * The handler will preventDefault all events when `true`.
58
+ */
59
+ preventDefault?: boolean;
60
+ /**
61
+ * Forces the handler to fire even for non intentional displacement (ignores
62
+ * the threshold). In that case, the intentional attribute from state will
63
+ * remain false until the threshold is reached.
64
+ */
65
+ triggerAllEvents?: boolean;
66
+ /**
67
+ * The elasticity coefficient of the gesture when going out of bounds. When
68
+ * set to true, the elasticiy coefficient will be defaulted to 0.15
69
+ */
70
+ rubberband?: boolean | number | Vector2;
71
+ /**
72
+ * A function that you can use to transform movement and offset values. Useful
73
+ * to map your screen coordinates to custom space coordinates such as a
74
+ * canvas.
75
+ */
76
+ transform?: (v: Vector2) => Vector2;
77
+ };
78
+
79
+ export type Bounds = {
80
+ top?: number;
81
+ bottom?: number;
82
+ left?: number;
83
+ right?: number;
84
+ };
85
+
86
+ export type CoordinatesConfig<Key extends CoordinatesKey = CoordinatesKey> = GestureOptions<Key> & {
87
+ /**
88
+ * The handler will only trigger if a movement is detected on the specified
89
+ * axis.
90
+ */
91
+ axis?: 'x' | 'y' | 'lock';
92
+ /**
93
+ * Limits the gesture `offset` to the specified bounds.
94
+ */
95
+ bounds?: Bounds | ((state: State[Key]) => Bounds);
96
+ /**
97
+ * Determines the number of pixels in one direction needed for axises to be
98
+ * calculated.
99
+ */
100
+ axisThreshold?: number;
101
+ };
102
+
103
+ export type PinchBounds = { min?: number; max?: number };
104
+ export type ModifierKey = 'ctrlKey' | 'altKey' | 'metaKey' | null;
105
+
106
+ export type PinchConfig = GestureOptions<'pinch'> & {
107
+ pointer?: {
108
+ /**
109
+ * If true, pinch will use touch events on touch-enabled devices.
110
+ */
111
+ touch?: boolean;
112
+ };
113
+ /**
114
+ * Limits the scale `offset` to the specified bounds.
115
+ */
116
+ scaleBounds?: PinchBounds | ((state: State['pinch']) => PinchBounds);
117
+ /**
118
+ * Limits the angle `offset` to the specified bounds.
119
+ */
120
+ angleBounds?: PinchBounds | ((state: State['pinch']) => PinchBounds);
121
+ /**
122
+ * Scales OR rotates when set to 'lock'.
123
+ */
124
+ axis?: 'lock' | undefined;
125
+ /**
126
+ * Key that triggers scale when using the wheel. Defaults to `'ctrlKey'`.
127
+ */
128
+ modifierKey?: ModifierKey | NonNullable<ModifierKey>[];
129
+ /**
130
+ * Whether wheel should trigger a pinch at all.
131
+ */
132
+ pinchOnWheel?: boolean;
133
+ };
134
+
135
+ export type DragBounds = Bounds | HTMLElement | { current: HTMLElement | null };
136
+
137
+ type MoveAndHoverMouseOnly = {
138
+ /**
139
+ * If false, onMove or onHover handlers will also fire on touch devices.
140
+ */
141
+ mouseOnly?: boolean;
142
+ };
143
+
144
+ export type MoveConfig = CoordinatesConfig<'move'> & MoveAndHoverMouseOnly;
145
+
146
+ export type HoverConfig = MoveAndHoverMouseOnly;
147
+
148
+ export type DragConfig = Omit<CoordinatesConfig<'drag'>, 'axisThreshold' | 'bounds'> & {
149
+ /**
150
+ * If true, the component won't trigger your drag logic if the user just clicked on the component.
151
+ */
152
+ filterTaps?: boolean;
153
+ /**
154
+ * The maximum total displacement a tap can have
155
+ */
156
+ tapsThreshold?: number;
157
+ /**
158
+ * Set this option to true when using with @react-three/fiber objects.
159
+ */
160
+ /**
161
+ * Limits the gesture `offset` to the specified bounds. Can be a ref or a dom
162
+ * node.
163
+ */
164
+ bounds?: DragBounds | ((state: State['drag']) => DragBounds);
165
+ pointer?: {
166
+ /**
167
+ * The buttons combination that would trigger the drag. Use `-1` to allow
168
+ * for any button combination to start the drag.
169
+ */
170
+ buttons?: number | number[];
171
+ /**
172
+ * If true, drag will use touch events on touch-enabled devices.
173
+ */
174
+ touch?: boolean;
175
+ /**
176
+ * If true, drag will use touch events on touch-enabled devices, and use
177
+ * mouse events on non touch devices.
178
+ */
179
+ mouse?: boolean;
180
+ /**
181
+ * If false, will disable KeyboardEvents that would otherwise trigger the
182
+ * drag gesture when the element is focused. Defaults to true.
183
+ */
184
+ keys?: boolean;
185
+ /**
186
+ * Doesn't use setPointerCapture when false and delegate drag handling to
187
+ * window
188
+ */
189
+ capture?: boolean;
190
+ /**
191
+ * Will perform a pointer lock when drag starts, and exit pointer lock when
192
+ * drag ends,
193
+ */
194
+ lock?: boolean;
195
+ };
196
+ swipe?: {
197
+ /**
198
+ * The minimum velocity per axis (in pixels / ms) the drag gesture needs to
199
+ * reach before the pointer is released.
200
+ */
201
+ velocity?: number | Vector2;
202
+ /**
203
+ * The minimum distance per axis (in pixels) the drag gesture needs to
204
+ * travel to trigger a swipe. Defaults to 50.
205
+ */
206
+ distance?: number | Vector2;
207
+ /**
208
+ * The maximum duration in milliseconds that a swipe is detected. Defaults
209
+ * to 250.
210
+ */
211
+ duration?: number;
212
+ };
213
+ /**
214
+ * If set, the drag will be triggered after the duration of the delay (in ms).
215
+ * When set to true, delay is defaulted to 250ms.
216
+ */
217
+ preventScroll?: boolean | number;
218
+ /**
219
+ * If set, the drag will allow scrolling in the direction of this axis until
220
+ * the preventScroll duration has elapsed. Defaults to only 'y'.
221
+ */
222
+ preventScrollAxis?: 'x' | 'y' | 'xy';
223
+ /**
224
+ * If set, the handler will be delayed for the duration of the delay (in ms)
225
+ * — or if the user starts moving. When set to true, delay is defaulted
226
+ * to 180ms.
227
+ */
228
+ delay?: boolean | number;
229
+ /**
230
+ * Key-number record that determines for each device (`'mouse'`, `'touch'`,
231
+ * `'pen'`) the number of pixels of drag in one direction needed for axises to
232
+ * be calculated.
233
+ */
234
+ axisThreshold?: Partial<Record<PointerType, number>>;
235
+ /**
236
+ * The distance (in pixels) emulated by arrow keys.
237
+ */
238
+ keyboardDisplacement?: number;
239
+ };
240
+
241
+ export type UserDragConfig = GenericOptions & DragConfig;
242
+ export type UserPinchConfig = GenericOptions & PinchConfig;
243
+ export type UserWheelConfig = GenericOptions & CoordinatesConfig<'wheel'>;
244
+ export type UserScrollConfig = GenericOptions & CoordinatesConfig<'scroll'>;
245
+ export type UserMoveConfig = GenericOptions & MoveConfig;
246
+ export type UserHoverConfig = GenericOptions & HoverConfig;
247
+
248
+ export type UserGestureConfig = GenericOptions & {
249
+ drag?: DragConfig;
250
+ wheel?: CoordinatesConfig<'wheel'>;
251
+ scroll?: CoordinatesConfig<'scroll'>;
252
+ move?: MoveConfig;
253
+ pinch?: PinchConfig;
254
+ hover?: { enabled?: boolean } & HoverConfig;
255
+ };
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import { DOMHandlers, EventHandler } from './utils';
7
+ import { FullGestureState, State, EventTypes } from './state';
8
+ import { GestureKey } from './config';
9
+
10
+ export type Handler<Key extends GestureKey, EventType = EventTypes[Key]> = (
11
+ state: Omit<FullGestureState<Key>, 'event'> & { event: EventType },
12
+ ) => any | void;
13
+
14
+ // if no type is provided in the user generic for a given key
15
+ // then return the default EventTypes that key
16
+ type check<T extends AnyHandlerEventTypes, Key extends GestureKey> = undefined extends T[Key]
17
+ ? EventTypes[Key]
18
+ : T[Key];
19
+
20
+ export type UserHandlers<T extends AnyHandlerEventTypes = EventTypes> = {
21
+ onDrag: Handler<'drag', check<T, 'drag'>>;
22
+ onDragStart: Handler<'drag', check<T, 'drag'>>;
23
+ onDragEnd: Handler<'drag', check<T, 'drag'>>;
24
+ onPinch: Handler<'pinch', check<T, 'pinch'>>;
25
+ onPinchStart: Handler<'pinch', check<T, 'pinch'>>;
26
+ onPinchEnd: Handler<'pinch', check<T, 'pinch'>>;
27
+ onWheel: Handler<'wheel', check<T, 'wheel'>>;
28
+ onWheelStart: Handler<'wheel', check<T, 'wheel'>>;
29
+ onWheelEnd: Handler<'wheel', check<T, 'wheel'>>;
30
+ onMove: Handler<'move', check<T, 'move'>>;
31
+ onMoveStart: Handler<'move', check<T, 'move'>>;
32
+ onMoveEnd: Handler<'move', check<T, 'move'>>;
33
+ onScroll: Handler<'scroll', check<T, 'scroll'>>;
34
+ onScrollStart: Handler<'scroll', check<T, 'scroll'>>;
35
+ onScrollEnd: Handler<'scroll', check<T, 'scroll'>>;
36
+ onHover: Handler<'hover', check<T, 'hover'>>;
37
+ };
38
+
39
+ type NativeHandlersKeys = keyof Omit<DOMHandlers, keyof UserHandlers>;
40
+
41
+ type GetEventType<Key extends NativeHandlersKeys> = DOMHandlers[Key] extends
42
+ | EventHandler<infer EventType>
43
+ | undefined
44
+ ? EventType
45
+ : UIEvent;
46
+
47
+ export type NativeHandlers<T extends AnyHandlerEventTypes = {}> = {
48
+ [key in NativeHandlersKeys]?: (
49
+ state: State['shared'] & {
50
+ event: undefined extends T[key] ? GetEventType<key> : T[key];
51
+ args: any;
52
+ },
53
+ ...args: any
54
+ ) => void;
55
+ };
56
+
57
+ // allows overriding the event type from the returned state in handlers
58
+ export type AnyHandlerEventTypes = Partial<
59
+ {
60
+ drag: any;
61
+ wheel: any;
62
+ scroll: any;
63
+ move: any;
64
+ pinch: any;
65
+ hover: any;
66
+ } & { [key in NativeHandlersKeys]: any }
67
+ >;
68
+
69
+ export type GestureHandlers<HandlerType extends AnyHandlerEventTypes = EventTypes> = Partial<
70
+ NativeHandlers<HandlerType> & UserHandlers<HandlerType>
71
+ >;
72
+
73
+ export type InternalHandlers = { [Key in GestureKey]?: Handler<Key, any> };
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ export * from './config';
7
+ export * from './internalConfig';
8
+ export * from './state';
9
+ export * from './utils';
10
+ export * from './handlers';
11
+ export * from './action';
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import { PointerType, Vector2 } from './utils';
7
+ import { State } from './state';
8
+ import { GestureKey, CoordinatesKey, ModifierKey } from './config';
9
+
10
+ export type InternalGenericOptions = {
11
+ target?: () => EventTarget;
12
+ eventOptions: AddEventListenerOptions;
13
+ window: EventTarget;
14
+ enabled: boolean;
15
+ transform?: (v: Vector2) => Vector2;
16
+ };
17
+
18
+ export type InternalGestureOptions<Key extends GestureKey = GestureKey> = {
19
+ enabled: boolean;
20
+ eventOptions: AddEventListenerOptions;
21
+ from: Vector2 | ((state: State[Key]) => Vector2);
22
+ threshold: Vector2;
23
+ preventDefault: boolean;
24
+ triggerAllEvents: boolean;
25
+ rubberband: Vector2;
26
+ bounds: [Vector2, Vector2] | ((state: State[Key]) => [Vector2, Vector2]);
27
+ hasCustomTransform: boolean;
28
+ transform: (v: Vector2) => Vector2;
29
+ };
30
+
31
+ export type InternalCoordinatesOptions<Key extends CoordinatesKey = CoordinatesKey> =
32
+ InternalGestureOptions<Key> & {
33
+ axis?: 'x' | 'y';
34
+ lockDirection: boolean;
35
+ axisThreshold: number;
36
+ };
37
+
38
+ export type InternalDragOptions = Omit<InternalCoordinatesOptions<'drag'>, 'axisThreshold'> & {
39
+ filterTaps: boolean;
40
+ tapsThreshold: number;
41
+ pointerButtons: number | number[];
42
+ pointerCapture: boolean;
43
+ preventScrollDelay?: number;
44
+ preventScrollAxis?: 'x' | 'y' | 'xy';
45
+ pointerLock: boolean;
46
+ keys: boolean;
47
+ device: 'pointer' | 'touch' | 'mouse';
48
+ swipe: {
49
+ velocity: Vector2;
50
+ distance: Vector2;
51
+ duration: number;
52
+ };
53
+ delay: number;
54
+ axisThreshold: Record<PointerType, number>;
55
+ keyboardDisplacement: number;
56
+ };
57
+
58
+ export type InternalPinchOptions = InternalGestureOptions<'pinch'> & {
59
+ /**
60
+ * When device is undefined, we'll be using wheel to zoom.
61
+ */
62
+ device: 'gesture' | 'pointer' | 'touch' | undefined;
63
+ lockDirection: boolean;
64
+ modifierKey: ModifierKey | NonNullable<ModifierKey>[];
65
+ pinchOnWheel: boolean;
66
+ };
67
+
68
+ type MoveAndHoverMouseOnly = {
69
+ mouseOnly: boolean;
70
+ };
71
+
72
+ export type InternalConfig = {
73
+ shared: InternalGenericOptions;
74
+ drag?: InternalDragOptions;
75
+ wheel?: InternalCoordinatesOptions<'wheel'>;
76
+ scroll?: InternalCoordinatesOptions<'scroll'>;
77
+ move?: InternalCoordinatesOptions<'move'> & MoveAndHoverMouseOnly;
78
+ hover?: InternalCoordinatesOptions<'hover'> & MoveAndHoverMouseOnly;
79
+ pinch?: InternalPinchOptions;
80
+ };
@@ -0,0 +1,275 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import { NonUndefined, Vector2, WebKitGestureEvent } from './utils';
7
+ import { GestureKey } from './config';
8
+
9
+ export type IngKey = 'dragging' | 'wheeling' | 'moving' | 'hovering' | 'scrolling' | 'pinching';
10
+
11
+ export type SharedGestureState = {
12
+ /**
13
+ * True if the element is being dragged.
14
+ */
15
+ dragging?: boolean;
16
+ /**
17
+ * True if the element is being wheeled.
18
+ */
19
+ wheeling?: boolean;
20
+ /**
21
+ * True if the element is being moved.
22
+ */
23
+ moving?: boolean;
24
+ /**
25
+ * True if the element is being hovered.
26
+ */
27
+ hovering?: boolean;
28
+ /**
29
+ * True if the element is being scrolled.
30
+ */
31
+ scrolling?: boolean;
32
+ /**
33
+ * True if the element is being pinched.
34
+ */
35
+ pinching?: boolean;
36
+ /**
37
+ * Number of fingers touching the screen.
38
+ */
39
+ touches: number;
40
+ /**
41
+ * True when the main mouse button or touch is pressed.
42
+ */
43
+ pressed: boolean;
44
+ /**
45
+ * Alias for pressed.
46
+ */
47
+ down: boolean;
48
+ /**
49
+ * True if the document is in lock mode.
50
+ */
51
+ locked: boolean;
52
+ /**
53
+ * Indicates which buttons are pressed (https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons).
54
+ */
55
+ buttons: number;
56
+ /**
57
+ * True when the Shift key is pressed.
58
+ */
59
+ shiftKey: boolean;
60
+ /**
61
+ * True when the Alt key is pressed.
62
+ */
63
+ altKey: boolean;
64
+ /**
65
+ * True when the Meta key is pressed.
66
+ */
67
+ metaKey: boolean;
68
+ /**
69
+ * True when the Control key is pressed.
70
+ */
71
+ ctrlKey: boolean;
72
+ };
73
+
74
+ export type CommonGestureState = {
75
+ _active: boolean;
76
+ _blocked: boolean;
77
+ _force: boolean;
78
+ _step: [false | number, false | number];
79
+ _movementBound: [false | number, false | number];
80
+ _values: Vector2;
81
+ _initial: Vector2;
82
+ _movement: Vector2;
83
+ _distance: Vector2;
84
+ _direction: Vector2;
85
+ _delta: Vector2;
86
+ _bounds: [Vector2, Vector2];
87
+ /**
88
+ * The event triggering the gesture.
89
+ */
90
+ event: UIEvent;
91
+ /**
92
+ * The event target.
93
+ */
94
+ target: EventTarget;
95
+ /**
96
+ * The event current target.
97
+ */
98
+ currentTarget: EventTarget;
99
+ /**
100
+ * True when the gesture is intentional (passed the threshold).
101
+ */
102
+ intentional: boolean;
103
+ /**
104
+ * Cumulative distance of the gesture. Deltas are summed with their absolute
105
+ * values.
106
+ */
107
+ distance: Vector2;
108
+ /**
109
+ * Displacement of the current gesture.
110
+ */
111
+ movement: Vector2;
112
+ /**
113
+ * Difference between the current movement and the previous movement.
114
+ */
115
+ delta: Vector2;
116
+ /**
117
+ * Cumulative displacements of all gestures (sum of all movements triggered
118
+ * by the handler)
119
+ */
120
+ offset: Vector2;
121
+ /**
122
+ * Offset when the gesture started.
123
+ */
124
+ lastOffset: Vector2;
125
+ /**
126
+ * Velocity vector.
127
+ */
128
+ velocity: Vector2;
129
+ /**
130
+ * Current raw values of the gesture. Can be coordinates or distance / angle
131
+ * depending on the gesture.
132
+ */
133
+ values: Vector2;
134
+ /**
135
+ * Raw values when the gesture started.
136
+ */
137
+ initial: Vector2;
138
+ /**
139
+ * Direction per axis. `-1` when going down, `1` when going up, `0` when still.
140
+ */
141
+ direction: Vector2;
142
+ /**
143
+ * Bound overflow per axis. `-1` when overflowing bounds to the left/top, `1` when overflowing bounds to the right/bottom.
144
+ */
145
+ overflow: Vector2;
146
+ /**
147
+ * True when it's the first event of the active gesture.
148
+ */
149
+ first: boolean;
150
+ /**
151
+ * True when it's the last event of the active gesture.
152
+ */
153
+ last: boolean;
154
+ /**
155
+ * True when the gesture is active.
156
+ */
157
+ active: boolean;
158
+ /**
159
+ * The timestamp (ms) of when the gesture started.
160
+ */
161
+ startTime: number;
162
+ /**
163
+ * The timestamp (ms) of the current event.
164
+ */
165
+ timeStamp: number;
166
+ /**
167
+ * Elapsed time (ms) of the current gesture.
168
+ */
169
+ elapsedTime: number;
170
+ /**
171
+ * Time delta (ms) with the previous event.
172
+ */
173
+ timeDelta: number;
174
+ /**
175
+ * Event type.
176
+ */
177
+ type: string;
178
+ /**
179
+ * Value returned by your handler on its previous run.
180
+ */
181
+ memo?: any;
182
+ /**
183
+ * The arguments passed to the bind function (only relevant in React when
184
+ * using `<div {...bind(someArgument)} />`)
185
+ */
186
+ args?: any;
187
+ };
188
+
189
+ export type CoordinatesState = CommonGestureState & {
190
+ /**
191
+ * The initial axis (x or y) of the gesture.
192
+ */
193
+ axis: 'x' | 'y' | undefined;
194
+ /**
195
+ * Pointer coordinates (alias to values)
196
+ */
197
+ xy: Vector2;
198
+ };
199
+
200
+ export type DragState = CoordinatesState & {
201
+ _pointerId?: number;
202
+ _pointerActive: boolean;
203
+ _keyboardActive: boolean;
204
+ _preventScroll: boolean;
205
+ _delayed: boolean;
206
+ /**
207
+ * True when the drag gesture has been canceled by the `cancel` function.
208
+ */
209
+ canceled: boolean;
210
+ /**
211
+ * Function that can be called to cancel the drag.
212
+ */
213
+ cancel(): void;
214
+ /**
215
+ * True if the drag gesture is recognized as a tap (ie when the displacement
216
+ * is lower than 3px per axis).
217
+ */
218
+ tap: boolean;
219
+ /**
220
+ * [swipeX, swipeY] is [0, 0] if no swipe detected, -1 or 1 otherwise.
221
+ */
222
+ swipe: Vector2;
223
+ };
224
+
225
+ export interface PinchState extends CommonGestureState {
226
+ _pointerEvents: Map<number, PointerEvent>;
227
+ _touchIds: [] | [number, number];
228
+ /**
229
+ * Distance and angle raw values (alias to values).
230
+ */
231
+ da: Vector2;
232
+ /**
233
+ * The initial axis (scale or angle) of the gesture.
234
+ */
235
+ axis: 'scale' | 'angle' | undefined;
236
+ /**
237
+ * Coordinates of the center of touch events, or the cursor when using wheel
238
+ * to pinch.
239
+ */
240
+ origin: Vector2;
241
+ /**
242
+ * The number of full rotation the current gesture has performed.
243
+ */
244
+ turns: number;
245
+ /**
246
+ * True when the pinch gesture has been canceled by the `cancel` function.
247
+ */
248
+ canceled: boolean;
249
+ /**
250
+ * Function that can be called to cancel the pinch.
251
+ */
252
+ cancel(): void;
253
+ }
254
+
255
+ export type EventTypes = {
256
+ drag: PointerEvent | TouchEvent | MouseEvent | KeyboardEvent;
257
+ wheel: WheelEvent;
258
+ scroll: UIEvent;
259
+ move: PointerEvent;
260
+ hover: PointerEvent;
261
+ pinch: PointerEvent | TouchEvent | WheelEvent | WebKitGestureEvent;
262
+ };
263
+
264
+ export interface State {
265
+ shared: SharedGestureState;
266
+ drag?: DragState & { event: EventTypes['drag'] };
267
+ wheel?: CoordinatesState & { event: EventTypes['wheel'] };
268
+ scroll?: CoordinatesState & { event: EventTypes['scroll'] };
269
+ move?: CoordinatesState & { event: EventTypes['move'] };
270
+ hover?: CoordinatesState & { event: EventTypes['hover'] };
271
+ pinch?: PinchState & { event: EventTypes['pinch'] };
272
+ }
273
+
274
+ export type FullGestureState<Key extends GestureKey> = SharedGestureState &
275
+ NonUndefined<State[Key]>;