@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.
- package/LICENSE +22 -0
- package/dist/index.cjs +0 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +0 -0
- package/dist/index.js.map +1 -0
- package/package.json +63 -0
- package/src/common/config-entity.ts +80 -0
- package/src/common/entity-data.ts +171 -0
- package/src/common/entity-manager-contribution.ts +12 -0
- package/src/common/entity-manager.ts +475 -0
- package/src/common/entity.ts +482 -0
- package/src/common/index.ts +22 -0
- package/src/common/playground-context.ts +35 -0
- package/src/common/playground-decorator-helper.ts +113 -0
- package/src/common/playground-decorators.ts +85 -0
- package/src/common/playground-schedule.ts +30 -0
- package/src/common/protect-wheel-area.ts +11 -0
- package/src/common/schema/index.ts +14 -0
- package/src/common/schema/node.ts +15 -0
- package/src/common/schema/opacity-schema.ts +19 -0
- package/src/common/schema/origin-schema.ts +35 -0
- package/src/common/schema/position-schema.ts +35 -0
- package/src/common/schema/rotation-schema.ts +19 -0
- package/src/common/schema/scale-schema.ts +35 -0
- package/src/common/schema/size-schema.ts +42 -0
- package/src/common/schema/skew-schema.ts +35 -0
- package/src/common/schema/transform-schema.ts +613 -0
- package/src/common/utils/bounds.spec.ts +229 -0
- package/src/common/utils/bounds.ts +176 -0
- package/src/common/utils/index.ts +6 -0
- package/src/composables/index.ts +16 -0
- package/src/composables/use-config-entity.ts +31 -0
- package/src/composables/use-entities.ts +26 -0
- package/src/composables/use-entity-data-from-context.ts +34 -0
- package/src/composables/use-entity-from-context.ts +31 -0
- package/src/composables/use-listen-events.ts +22 -0
- package/src/composables/use-playground-container.ts +16 -0
- package/src/composables/use-playground-context.ts +15 -0
- package/src/composables/use-playground-drag.ts +31 -0
- package/src/composables/use-playground.ts +16 -0
- package/src/composables/use-refresh.ts +6 -0
- package/src/composables/use-service.ts +17 -0
- package/src/core/index.ts +8 -0
- package/src/core/layer/config/editor-state-config-entity.ts +180 -0
- package/src/core/layer/config/index.ts +7 -0
- package/src/core/layer/config/playground-config-entity.ts +604 -0
- package/src/core/layer/index.ts +8 -0
- package/src/core/layer/layer.ts +248 -0
- package/src/core/layer/playground-layer.ts +547 -0
- package/src/core/pipeline/index.ts +10 -0
- package/src/core/pipeline/pipeline-entities-selector.ts +200 -0
- package/src/core/pipeline/pipeline-entities.ts +230 -0
- package/src/core/pipeline/pipeline-registry.ts +344 -0
- package/src/core/pipeline/pipeline-renderer.ts +248 -0
- package/src/core/pipeline/pipeline-vue-utils.ts +96 -0
- package/src/core/pipeline/pipeline.ts +28 -0
- package/src/core/utils/index.ts +12 -0
- package/src/core/utils/inject-provider-decorators.ts +27 -0
- package/src/core/utils/lazy-inject-decorators.ts +38 -0
- package/src/core/utils/mouse-touch-event.ts +120 -0
- package/src/core/utils/playground-drag.ts +511 -0
- package/src/core/utils/playground-gesture.spec.ts +135 -0
- package/src/core/utils/playground-gesture.ts +118 -0
- package/src/core/utils/tween.ts +156 -0
- package/src/core/utils/use-gesture/core/Controller.ts +212 -0
- package/src/core/utils/use-gesture/core/EventStore.ts +46 -0
- package/src/core/utils/use-gesture/core/TimeoutStore.ts +28 -0
- package/src/core/utils/use-gesture/core/actions.ts +63 -0
- package/src/core/utils/use-gesture/core/config/commonConfigResolver.ts +86 -0
- package/src/core/utils/use-gesture/core/config/coordinatesConfigResolver.ts +48 -0
- package/src/core/utils/use-gesture/core/config/dragConfigResolver.ts +140 -0
- package/src/core/utils/use-gesture/core/config/hoverConfigResolver.ts +11 -0
- package/src/core/utils/use-gesture/core/config/moveConfigResolver.ts +11 -0
- package/src/core/utils/use-gesture/core/config/pinchConfigResolver.ts +59 -0
- package/src/core/utils/use-gesture/core/config/resolver.ts +70 -0
- package/src/core/utils/use-gesture/core/config/scrollConfigResolver.ts +8 -0
- package/src/core/utils/use-gesture/core/config/sharedConfigResolver.ts +28 -0
- package/src/core/utils/use-gesture/core/config/support.ts +52 -0
- package/src/core/utils/use-gesture/core/config/wheelConfigResolver.ts +8 -0
- package/src/core/utils/use-gesture/core/engines/CoordinatesEngine.ts +78 -0
- package/src/core/utils/use-gesture/core/engines/DragEngine.ts +403 -0
- package/src/core/utils/use-gesture/core/engines/Engine.ts +406 -0
- package/src/core/utils/use-gesture/core/engines/HoverEngine.ts +43 -0
- package/src/core/utils/use-gesture/core/engines/MoveEngine.ts +52 -0
- package/src/core/utils/use-gesture/core/engines/PinchEngine.ts +345 -0
- package/src/core/utils/use-gesture/core/engines/ScrollEngine.ts +42 -0
- package/src/core/utils/use-gesture/core/engines/WheelEngine.ts +48 -0
- package/src/core/utils/use-gesture/core/index.ts +7 -0
- package/src/core/utils/use-gesture/core/parser.ts +92 -0
- package/src/core/utils/use-gesture/core/types/action.ts +19 -0
- package/src/core/utils/use-gesture/core/types/config.ts +255 -0
- package/src/core/utils/use-gesture/core/types/handlers.ts +73 -0
- package/src/core/utils/use-gesture/core/types/index.ts +11 -0
- package/src/core/utils/use-gesture/core/types/internalConfig.ts +80 -0
- package/src/core/utils/use-gesture/core/types/state.ts +275 -0
- package/src/core/utils/use-gesture/core/types/utils.ts +204 -0
- package/src/core/utils/use-gesture/core/types.ts +8 -0
- package/src/core/utils/use-gesture/core/utils/events.ts +158 -0
- package/src/core/utils/use-gesture/core/utils/fn.ts +32 -0
- package/src/core/utils/use-gesture/core/utils/maths.ts +63 -0
- package/src/core/utils/use-gesture/core/utils/state.ts +24 -0
- package/src/core/utils/use-gesture/core/utils.ts +8 -0
- package/src/core/utils/use-gesture/index.ts +6 -0
- package/src/core/utils/use-gesture/vanilla/DragGesture.ts +27 -0
- package/src/core/utils/use-gesture/vanilla/Gesture.ts +45 -0
- package/src/core/utils/use-gesture/vanilla/HoverGesture.ts +27 -0
- package/src/core/utils/use-gesture/vanilla/MoveGesture.ts +27 -0
- package/src/core/utils/use-gesture/vanilla/PinchGesture.ts +27 -0
- package/src/core/utils/use-gesture/vanilla/Recognizer.ts +43 -0
- package/src/core/utils/use-gesture/vanilla/ScrollGesture.ts +27 -0
- package/src/core/utils/use-gesture/vanilla/WheelGesture.ts +27 -0
- package/src/core/utils/use-gesture/vanilla/createGesture.ts +18 -0
- package/src/core/utils/use-gesture/vanilla/index.ts +18 -0
- package/src/env.d.ts +10 -0
- package/src/index.ts +17 -0
- package/src/playground-config.ts +70 -0
- package/src/playground-container.ts +129 -0
- package/src/playground-contribution.ts +81 -0
- package/src/playground-mock-tools.ts +143 -0
- package/src/playground.ts +401 -0
- package/src/plugin/index.ts +6 -0
- package/src/plugin/plugin.ts +226 -0
- package/src/services/clipboard-service.ts +40 -0
- package/src/services/context-menu-service.ts +25 -0
- package/src/services/index.ts +10 -0
- package/src/services/logger-service.ts +49 -0
- package/src/services/selection-service.ts +54 -0
- package/src/services/storage-service.ts +65 -0
- package/src/vue/index.ts +8 -0
- package/src/vue/playground-vue-context.ts +22 -0
- package/src/vue/playground-vue-provider.ts +115 -0
- package/src/vue/playground-vue-renderer.vue +44 -0
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { V, computeRubberband } from '../utils/maths';
|
|
7
|
+
import { call } from '../utils/fn';
|
|
8
|
+
import { getEventDetails } from '../utils/events';
|
|
9
|
+
import { GestureKey, IngKey, State, Vector2 } from '../types';
|
|
10
|
+
import { NonUndefined } from '../types';
|
|
11
|
+
import { Controller } from '../Controller';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The lib doesn't compute the kinematics on the last event of the gesture
|
|
15
|
+
* (i.e. for a drag gesture, the `pointerup` coordinates will generally match the
|
|
16
|
+
* last `pointermove` coordinates which would result in all drags ending with a
|
|
17
|
+
* `[0,0]` velocity). However, when the timestamp difference between the last
|
|
18
|
+
* event (ie pointerup) and the before last event (ie pointermove) is greater
|
|
19
|
+
* than BEFORE_LAST_KINEMATICS_DELAY, the kinematics are computed (which would
|
|
20
|
+
* mean that if you release your drag after stopping for more than
|
|
21
|
+
* BEFORE_LAST_KINEMATICS_DELAY, the velocity will be indeed 0).
|
|
22
|
+
*
|
|
23
|
+
* See https://github.com/pmndrs/use-gesture/issues/332 for more details.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
const BEFORE_LAST_KINEMATICS_DELAY = 32;
|
|
27
|
+
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
29
|
+
export interface Engine<Key extends GestureKey> {
|
|
30
|
+
/**
|
|
31
|
+
* Function that some gestures can use to add initilization
|
|
32
|
+
* properties to the state when it is created.
|
|
33
|
+
*/
|
|
34
|
+
init?(): void;
|
|
35
|
+
/**
|
|
36
|
+
* Setup function that some gestures can use to set additional properties of
|
|
37
|
+
* the state when the gesture starts.
|
|
38
|
+
*/
|
|
39
|
+
setup?(): void;
|
|
40
|
+
/**
|
|
41
|
+
* Function used by some gestures to determine the intentionality of a
|
|
42
|
+
* a movement depending on thresholds. The intent function can change the
|
|
43
|
+
* `state._active` or `state._blocked` flags if the gesture isn't intentional.
|
|
44
|
+
* @param event
|
|
45
|
+
*/
|
|
46
|
+
axisIntent?(event?: UIEvent): void;
|
|
47
|
+
|
|
48
|
+
restrictToAxis?(movement: Vector2): void;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export abstract class Engine<Key extends GestureKey> {
|
|
52
|
+
/**
|
|
53
|
+
* The Controller handling state.
|
|
54
|
+
*/
|
|
55
|
+
ctrl: Controller;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The gesture key ('drag' | 'pinch' | 'wheel' | 'scroll' | 'move' | 'hover')
|
|
59
|
+
*/
|
|
60
|
+
readonly key: Key;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The key representing the active state of the gesture in the shared state.
|
|
64
|
+
* ('dragging' | 'pinching' | 'wheeling' | 'scrolling' | 'moving' | 'hovering')
|
|
65
|
+
*/
|
|
66
|
+
abstract readonly ingKey: IngKey;
|
|
67
|
+
/**
|
|
68
|
+
* The arguments passed to the `bind` function.
|
|
69
|
+
*/
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* State prop that aliases state values (`xy` or `da`).
|
|
73
|
+
*/
|
|
74
|
+
abstract readonly aliasKey: string;
|
|
75
|
+
|
|
76
|
+
args: any[];
|
|
77
|
+
|
|
78
|
+
constructor(ctrl: Controller, args: any[], key: Key) {
|
|
79
|
+
this.ctrl = ctrl;
|
|
80
|
+
this.args = args;
|
|
81
|
+
this.key = key;
|
|
82
|
+
|
|
83
|
+
if (!this.state) {
|
|
84
|
+
this.state = {} as any;
|
|
85
|
+
this.computeValues([0, 0]);
|
|
86
|
+
this.computeInitial();
|
|
87
|
+
|
|
88
|
+
if (this.init) this.init();
|
|
89
|
+
this.reset();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Function implemented by gestures that compute the offset from the state
|
|
95
|
+
* movement.
|
|
96
|
+
*/
|
|
97
|
+
abstract computeOffset(): void;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Function implemented by the gestures that compute the movement from the
|
|
101
|
+
* corrected offset (after bounds and potential rubberbanding).
|
|
102
|
+
*/
|
|
103
|
+
abstract computeMovement(): void;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Executes the bind function so that listeners are properly set by the
|
|
107
|
+
* Controller.
|
|
108
|
+
* @param bindFunction
|
|
109
|
+
*/
|
|
110
|
+
abstract bind(
|
|
111
|
+
bindFunction: (
|
|
112
|
+
device: string,
|
|
113
|
+
action: string,
|
|
114
|
+
handler: (event: any) => void,
|
|
115
|
+
options?: AddEventListenerOptions,
|
|
116
|
+
) => void,
|
|
117
|
+
): void;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Shortcut to the gesture state read from the Controller.
|
|
121
|
+
*/
|
|
122
|
+
get state() {
|
|
123
|
+
return this.ctrl.state[this.key]!;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
set state(state) {
|
|
127
|
+
this.ctrl.state[this.key] = state;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Shortcut to the shared state read from the Controller
|
|
132
|
+
*/
|
|
133
|
+
get shared() {
|
|
134
|
+
return this.ctrl.state.shared;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Shortcut to the gesture event store read from the Controller.
|
|
139
|
+
*/
|
|
140
|
+
get eventStore() {
|
|
141
|
+
return this.ctrl.gestureEventStores[this.key]!;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Shortcut to the gesture timeout store read from the Controller.
|
|
146
|
+
*/
|
|
147
|
+
get timeoutStore() {
|
|
148
|
+
return this.ctrl.gestureTimeoutStores[this.key]!;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Shortcut to the gesture config read from the Controller.
|
|
153
|
+
*/
|
|
154
|
+
get config() {
|
|
155
|
+
return this.ctrl.config[this.key]!;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Shortcut to the shared config read from the Controller.
|
|
160
|
+
*/
|
|
161
|
+
get sharedConfig() {
|
|
162
|
+
return this.ctrl.config.shared;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Shortcut to the gesture handler read from the Controller.
|
|
167
|
+
*/
|
|
168
|
+
get handler() {
|
|
169
|
+
return this.ctrl.handlers[this.key]!;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
reset() {
|
|
173
|
+
const { state, shared, ingKey, args } = this;
|
|
174
|
+
shared[ingKey] = state._active = state.active = state._blocked = state._force = false;
|
|
175
|
+
state._step = [false, false];
|
|
176
|
+
state.intentional = false;
|
|
177
|
+
state._movement = [0, 0];
|
|
178
|
+
state._distance = [0, 0];
|
|
179
|
+
state._direction = [0, 0];
|
|
180
|
+
state._delta = [0, 0];
|
|
181
|
+
// prettier-ignore
|
|
182
|
+
state._bounds = [[-Infinity, Infinity], [-Infinity, Infinity]]
|
|
183
|
+
state.args = args;
|
|
184
|
+
state.axis = undefined;
|
|
185
|
+
state.memo = undefined;
|
|
186
|
+
state.elapsedTime = state.timeDelta = 0;
|
|
187
|
+
state.direction = [0, 0];
|
|
188
|
+
state.distance = [0, 0];
|
|
189
|
+
state.overflow = [0, 0];
|
|
190
|
+
state._movementBound = [false, false];
|
|
191
|
+
state.velocity = [0, 0];
|
|
192
|
+
state.movement = [0, 0];
|
|
193
|
+
state.delta = [0, 0];
|
|
194
|
+
state.timeStamp = 0;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Function ran at the start of the gesture.
|
|
199
|
+
* @param event
|
|
200
|
+
*/
|
|
201
|
+
start(event: NonUndefined<State[Key]>['event']) {
|
|
202
|
+
const state = this.state;
|
|
203
|
+
const config = this.config;
|
|
204
|
+
if (!state._active) {
|
|
205
|
+
this.reset();
|
|
206
|
+
this.computeInitial();
|
|
207
|
+
|
|
208
|
+
state._active = true;
|
|
209
|
+
state.target = event.target!;
|
|
210
|
+
state.currentTarget = event.currentTarget!;
|
|
211
|
+
state.lastOffset = config.from ? call(config.from, state) : state.offset;
|
|
212
|
+
state.offset = state.lastOffset;
|
|
213
|
+
state.startTime = state.timeStamp = event.timeStamp;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Assign raw values to `state._values` and transformed values to
|
|
219
|
+
* `state.values`.
|
|
220
|
+
* @param values
|
|
221
|
+
*/
|
|
222
|
+
computeValues(values: Vector2) {
|
|
223
|
+
const state = this.state;
|
|
224
|
+
state._values = values;
|
|
225
|
+
// transforming values into user-defined coordinates (#402)
|
|
226
|
+
state.values = this.config.transform(values);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Assign `state._values` to `state._initial` and transformed `state.values` to
|
|
231
|
+
* `state.initial`.
|
|
232
|
+
* @param values
|
|
233
|
+
*/
|
|
234
|
+
computeInitial() {
|
|
235
|
+
const state = this.state;
|
|
236
|
+
state._initial = state._values;
|
|
237
|
+
state.initial = state.values;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Computes all sorts of state attributes, including kinematics.
|
|
242
|
+
* @param event
|
|
243
|
+
*/
|
|
244
|
+
compute(event?: NonUndefined<State[Key]>['event']) {
|
|
245
|
+
const { state, config, shared } = this;
|
|
246
|
+
state.args = this.args;
|
|
247
|
+
|
|
248
|
+
let dt = 0;
|
|
249
|
+
|
|
250
|
+
if (event) {
|
|
251
|
+
// sets the shared state with event properties
|
|
252
|
+
state.event = event;
|
|
253
|
+
// if config.preventDefault is true, then preventDefault
|
|
254
|
+
if (config.preventDefault && event.cancelable) state.event.preventDefault();
|
|
255
|
+
state.type = event.type;
|
|
256
|
+
shared.touches = this.ctrl.pointerIds.size || this.ctrl.touchIds.size;
|
|
257
|
+
shared.locked = !!document.pointerLockElement;
|
|
258
|
+
Object.assign(shared, getEventDetails(event));
|
|
259
|
+
shared.down = shared.pressed = shared.buttons % 2 === 1 || shared.touches > 0;
|
|
260
|
+
|
|
261
|
+
// sets time stamps
|
|
262
|
+
dt = event.timeStamp - state.timeStamp;
|
|
263
|
+
state.timeStamp = event.timeStamp;
|
|
264
|
+
state.elapsedTime = state.timeStamp - state.startTime;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// only compute _distance if the state is active otherwise we might compute it
|
|
268
|
+
// twice when the gesture ends because state._delta wouldn't have changed on
|
|
269
|
+
// the last frame.
|
|
270
|
+
if (state._active) {
|
|
271
|
+
const _absoluteDelta = state._delta.map(Math.abs) as Vector2;
|
|
272
|
+
V.addTo(state._distance, _absoluteDelta);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// let's run intentionality check.
|
|
276
|
+
if (this.axisIntent) this.axisIntent(event);
|
|
277
|
+
|
|
278
|
+
// _movement is calculated by each gesture engine
|
|
279
|
+
const [_m0, _m1] = state._movement;
|
|
280
|
+
const [t0, t1] = config.threshold;
|
|
281
|
+
|
|
282
|
+
const { _step, values } = state;
|
|
283
|
+
|
|
284
|
+
if (config.hasCustomTransform) {
|
|
285
|
+
// When the user is using a custom transform, we're using `_step` to store
|
|
286
|
+
// the first value passing the threshold.
|
|
287
|
+
if (_step[0] === false) _step[0] = Math.abs(_m0) >= t0 && values[0];
|
|
288
|
+
if (_step[1] === false) _step[1] = Math.abs(_m1) >= t1 && values[1];
|
|
289
|
+
} else {
|
|
290
|
+
// `_step` will hold the threshold at which point the gesture was triggered.
|
|
291
|
+
// The threshold is signed depending on which direction triggered it.
|
|
292
|
+
if (_step[0] === false) _step[0] = Math.abs(_m0) >= t0 && Math.sign(_m0) * t0;
|
|
293
|
+
if (_step[1] === false) _step[1] = Math.abs(_m1) >= t1 && Math.sign(_m1) * t1;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
state.intentional = _step[0] !== false || _step[1] !== false;
|
|
297
|
+
|
|
298
|
+
if (!state.intentional) return;
|
|
299
|
+
|
|
300
|
+
const movement: Vector2 = [0, 0];
|
|
301
|
+
|
|
302
|
+
if (config.hasCustomTransform) {
|
|
303
|
+
const [v0, v1] = values;
|
|
304
|
+
movement[0] = _step[0] !== false ? v0 - _step[0] : 0;
|
|
305
|
+
movement[1] = _step[1] !== false ? v1 - _step[1] : 0;
|
|
306
|
+
} else {
|
|
307
|
+
movement[0] = _step[0] !== false ? _m0 - _step[0] : 0;
|
|
308
|
+
movement[1] = _step[1] !== false ? _m1 - _step[1] : 0;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
if (this.restrictToAxis && !state._blocked) this.restrictToAxis(movement);
|
|
312
|
+
|
|
313
|
+
const previousOffset = state.offset;
|
|
314
|
+
|
|
315
|
+
const gestureIsActive = (state._active && !state._blocked) || state.active;
|
|
316
|
+
|
|
317
|
+
if (gestureIsActive) {
|
|
318
|
+
state.first = state._active && !state.active;
|
|
319
|
+
state.last = !state._active && state.active;
|
|
320
|
+
state.active = shared[this.ingKey] = state._active;
|
|
321
|
+
|
|
322
|
+
if (event) {
|
|
323
|
+
if (state.first) {
|
|
324
|
+
if ('bounds' in config) state._bounds = call(config.bounds, state);
|
|
325
|
+
if (this.setup) this.setup();
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
state.movement = movement;
|
|
329
|
+
this.computeOffset();
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
const [ox, oy] = state.offset;
|
|
334
|
+
const [[x0, x1], [y0, y1]] = state._bounds;
|
|
335
|
+
state.overflow = [ox < x0 ? -1 : ox > x1 ? 1 : 0, oy < y0 ? -1 : oy > y1 ? 1 : 0];
|
|
336
|
+
|
|
337
|
+
// _movementBound will store the latest _movement value
|
|
338
|
+
// before it went off bounds.
|
|
339
|
+
state._movementBound[0] = state.overflow[0]
|
|
340
|
+
? state._movementBound[0] === false
|
|
341
|
+
? state._movement[0]
|
|
342
|
+
: state._movementBound[0]
|
|
343
|
+
: false;
|
|
344
|
+
|
|
345
|
+
state._movementBound[1] = state.overflow[1]
|
|
346
|
+
? state._movementBound[1] === false
|
|
347
|
+
? state._movement[1]
|
|
348
|
+
: state._movementBound[1]
|
|
349
|
+
: false;
|
|
350
|
+
|
|
351
|
+
// @ts-ignore
|
|
352
|
+
const rubberband: Vector2 = state._active ? config.rubberband || [0, 0] : [0, 0];
|
|
353
|
+
state.offset = computeRubberband(state._bounds, state.offset, rubberband);
|
|
354
|
+
state.delta = V.sub(state.offset, previousOffset);
|
|
355
|
+
|
|
356
|
+
this.computeMovement();
|
|
357
|
+
|
|
358
|
+
if (gestureIsActive && (!state.last || dt > BEFORE_LAST_KINEMATICS_DELAY)) {
|
|
359
|
+
state.delta = V.sub(state.offset, previousOffset);
|
|
360
|
+
const absoluteDelta = state.delta.map(Math.abs) as Vector2;
|
|
361
|
+
|
|
362
|
+
V.addTo(state.distance, absoluteDelta);
|
|
363
|
+
state.direction = state.delta.map(Math.sign) as Vector2;
|
|
364
|
+
state._direction = state._delta.map(Math.sign) as Vector2;
|
|
365
|
+
|
|
366
|
+
// calculates kinematics unless the gesture starts or ends or if the
|
|
367
|
+
// dt === 0 (which can happen on high frame rate monitors, see issue #581)
|
|
368
|
+
// because of privacy protection:
|
|
369
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/Event/timeStamp#reduced_time_precision
|
|
370
|
+
if (!state.first && dt > 0) {
|
|
371
|
+
state.velocity = [absoluteDelta[0] / dt, absoluteDelta[1] / dt];
|
|
372
|
+
state.timeDelta = dt;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* Fires the gesture handler.
|
|
379
|
+
*/
|
|
380
|
+
emit() {
|
|
381
|
+
const state = this.state;
|
|
382
|
+
const shared = this.shared;
|
|
383
|
+
const config = this.config;
|
|
384
|
+
|
|
385
|
+
if (!state._active) this.clean();
|
|
386
|
+
|
|
387
|
+
// we don't trigger the handler if the gesture is blocked or non intentional,
|
|
388
|
+
// unless the `_force` flag was set or the `triggerAllEvents` option was set
|
|
389
|
+
// to true in the config.
|
|
390
|
+
if ((state._blocked || !state.intentional) && !state._force && !config.triggerAllEvents) return;
|
|
391
|
+
|
|
392
|
+
// @ts-ignore
|
|
393
|
+
const memo = this.handler({ ...shared, ...state, [this.aliasKey]: state.values });
|
|
394
|
+
|
|
395
|
+
// Sets memo to the returned value of the handler (unless it's undefined)
|
|
396
|
+
if (memo !== undefined) state.memo = memo;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* Cleans the gesture timeouts and event listeners.
|
|
401
|
+
*/
|
|
402
|
+
clean() {
|
|
403
|
+
this.eventStore.clean();
|
|
404
|
+
this.timeoutStore.clean();
|
|
405
|
+
}
|
|
406
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { V } from '../utils/maths';
|
|
7
|
+
import { pointerValues } from '../utils/events';
|
|
8
|
+
import { CoordinatesEngine } from './CoordinatesEngine';
|
|
9
|
+
|
|
10
|
+
export class HoverEngine extends CoordinatesEngine<'hover'> {
|
|
11
|
+
ingKey = 'hovering' as const;
|
|
12
|
+
|
|
13
|
+
enter(event: PointerEvent) {
|
|
14
|
+
if (this.config.mouseOnly && event.pointerType !== 'mouse') return;
|
|
15
|
+
this.start(event);
|
|
16
|
+
this.computeValues(pointerValues(event));
|
|
17
|
+
|
|
18
|
+
this.compute(event);
|
|
19
|
+
this.emit();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
leave(event: PointerEvent) {
|
|
23
|
+
if (this.config.mouseOnly && event.pointerType !== 'mouse') return;
|
|
24
|
+
|
|
25
|
+
const state = this.state;
|
|
26
|
+
if (!state._active) return;
|
|
27
|
+
|
|
28
|
+
state._active = false;
|
|
29
|
+
const values = pointerValues(event);
|
|
30
|
+
state._movement = state._delta = V.sub(values, state._values);
|
|
31
|
+
|
|
32
|
+
this.computeValues(values);
|
|
33
|
+
this.compute(event);
|
|
34
|
+
|
|
35
|
+
state.delta = state.movement;
|
|
36
|
+
this.emit();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
bind(bindFunction: any) {
|
|
40
|
+
bindFunction('pointer', 'enter', this.enter.bind(this));
|
|
41
|
+
bindFunction('pointer', 'leave', this.leave.bind(this));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { V } from '../utils/maths';
|
|
7
|
+
import { pointerValues } from '../utils/events';
|
|
8
|
+
import { CoordinatesEngine } from './CoordinatesEngine';
|
|
9
|
+
|
|
10
|
+
export class MoveEngine extends CoordinatesEngine<'move'> {
|
|
11
|
+
ingKey = 'moving' as const;
|
|
12
|
+
|
|
13
|
+
move(event: PointerEvent) {
|
|
14
|
+
if (this.config.mouseOnly && event.pointerType !== 'mouse') return;
|
|
15
|
+
if (!this.state._active) this.moveStart(event);
|
|
16
|
+
else this.moveChange(event);
|
|
17
|
+
this.timeoutStore.add('moveEnd', this.moveEnd.bind(this));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
moveStart(event: PointerEvent) {
|
|
21
|
+
this.start(event);
|
|
22
|
+
this.computeValues(pointerValues(event));
|
|
23
|
+
this.compute(event);
|
|
24
|
+
this.computeInitial();
|
|
25
|
+
this.emit();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
moveChange(event: PointerEvent) {
|
|
29
|
+
if (!this.state._active) return;
|
|
30
|
+
const values = pointerValues(event);
|
|
31
|
+
const state = this.state;
|
|
32
|
+
state._delta = V.sub(values, state._values);
|
|
33
|
+
V.addTo(state._movement, state._delta);
|
|
34
|
+
|
|
35
|
+
this.computeValues(values);
|
|
36
|
+
|
|
37
|
+
this.compute(event);
|
|
38
|
+
this.emit();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
moveEnd(event?: PointerEvent) {
|
|
42
|
+
if (!this.state._active) return;
|
|
43
|
+
this.state._active = false;
|
|
44
|
+
this.compute(event);
|
|
45
|
+
this.emit();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
bind(bindFunction: any) {
|
|
49
|
+
bindFunction('pointer', 'change', this.move.bind(this));
|
|
50
|
+
bindFunction('pointer', 'leave', this.moveEnd.bind(this));
|
|
51
|
+
}
|
|
52
|
+
}
|