@predy-js/render-interface 0.3.4-beta.17 → 0.3.4-beta.19
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/dist/index.js +2 -705
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3 -700
- package/dist/index.mjs.map +1 -1
- package/dist/src/module.d.ts +0 -2
- package/dist/statistic.js +1 -1
- package/dist/types/index.d.ts +0 -1
- package/package.json +1 -1
- package/types/index.ts +0 -1
- package/dist/src/render/EventSystem.d.ts +0 -22
- package/dist/src/render/event/H5Handler.d.ts +0 -15
- package/dist/src/render/event/RNHandler.d.ts +0 -10
- package/dist/src/render/event/UniversalRecognizer.d.ts +0 -52
- package/dist/src/render/event/WebHandler.d.ts +0 -16
- package/dist/types/EventSystem.d.ts +0 -133
- package/types/EventSystem.ts +0 -226
package/dist/index.js
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
* Name: @predy-js/render-interface
|
3
3
|
* Description: undefined
|
4
4
|
* Author: undefined
|
5
|
-
* Version: v0.3.4-beta.
|
5
|
+
* Version: v0.3.4-beta.19
|
6
6
|
*/
|
7
7
|
|
8
8
|
'use strict';
|
@@ -174,89 +174,6 @@ exports.TextureSourceType = void 0;
|
|
174
174
|
|
175
175
|
var GPUBufferOptionsMemoryShared = 1 << 1;
|
176
176
|
|
177
|
-
exports.EventSystemEnv = void 0;
|
178
|
-
(function (EventSystemEnv) {
|
179
|
-
EventSystemEnv[EventSystemEnv["web"] = 0] = "web";
|
180
|
-
EventSystemEnv[EventSystemEnv["h5"] = 1] = "h5";
|
181
|
-
EventSystemEnv[EventSystemEnv["rn"] = 2] = "rn";
|
182
|
-
EventSystemEnv[EventSystemEnv["ios"] = 3] = "ios";
|
183
|
-
EventSystemEnv[EventSystemEnv["android"] = 4] = "android";
|
184
|
-
EventSystemEnv[EventSystemEnv["harmony"] = 5] = "harmony";
|
185
|
-
})(exports.EventSystemEnv || (exports.EventSystemEnv = {}));
|
186
|
-
exports.RecognizerState = void 0;
|
187
|
-
(function (RecognizerState) {
|
188
|
-
RecognizerState[RecognizerState["UNDETERMINED"] = 0] = "UNDETERMINED";
|
189
|
-
RecognizerState[RecognizerState["FAILED"] = 1] = "FAILED";
|
190
|
-
RecognizerState[RecognizerState["BEGAN"] = 2] = "BEGAN";
|
191
|
-
RecognizerState[RecognizerState["CANCELLED"] = 3] = "CANCELLED";
|
192
|
-
RecognizerState[RecognizerState["ACTIVE"] = 4] = "ACTIVE";
|
193
|
-
RecognizerState[RecognizerState["END"] = 5] = "END";
|
194
|
-
})(exports.RecognizerState || (exports.RecognizerState = {}));
|
195
|
-
var EVENT_TYPE_CLICK = 'click';
|
196
|
-
var EVENT_TYPE_TOUCH_START = 'touchstart';
|
197
|
-
var EVENT_TYPE_TOUCH_MOVE = 'touchmove';
|
198
|
-
var EVENT_TYPE_TOUCH_END = 'touchend';
|
199
|
-
var EVENT_TYPE_TOUCH_CANCEL = 'touchcancel';
|
200
|
-
exports.PredyNativeEventType = void 0;
|
201
|
-
(function (PredyNativeEventType) {
|
202
|
-
PredyNativeEventType[PredyNativeEventType["touchstart"] = 1] = "touchstart";
|
203
|
-
PredyNativeEventType[PredyNativeEventType["touchmove"] = 2] = "touchmove";
|
204
|
-
PredyNativeEventType[PredyNativeEventType["touchend"] = 3] = "touchend";
|
205
|
-
})(exports.PredyNativeEventType || (exports.PredyNativeEventType = {}));
|
206
|
-
// // 扩展事件类型
|
207
|
-
// export enum EVENT_TYPE {
|
208
|
-
// // 基础事件
|
209
|
-
// START = 'start',
|
210
|
-
// MOVE = 'move',
|
211
|
-
// END = 'end',
|
212
|
-
// CANCEL = 'cancel',
|
213
|
-
// // 手势事件
|
214
|
-
// PINCH_START = 'pinchstart',
|
215
|
-
// PINCH_MOVE = 'pinchmove',
|
216
|
-
// PINCH_END = 'pinchend',
|
217
|
-
// PINCH = 'pinch',
|
218
|
-
// ROTATE_START = 'rotatestart',
|
219
|
-
// ROTATE_MOVE = 'rotatemove',
|
220
|
-
// ROTATE_END = 'rotateend',
|
221
|
-
// ROTATE = 'rotate',
|
222
|
-
// PAN_START = 'panstart',
|
223
|
-
// PAN_MOVE = 'panmove',
|
224
|
-
// PAN_END = 'panend',
|
225
|
-
// PAN = 'pan',
|
226
|
-
// SWIPE = 'swipe',
|
227
|
-
// TAP = 'tap',
|
228
|
-
// }
|
229
|
-
// export type PredyGestureEventArg = {
|
230
|
-
// type: EVENT_TYPE,
|
231
|
-
// touches: PredyTouch[], // 当前所有触点
|
232
|
-
// center: vec2, // 手势中心点
|
233
|
-
// scale?: number, // 当前缩放比例(相对于初始)
|
234
|
-
// rotation?: number, // 旋转角度(弧度,相对于初始)
|
235
|
-
// velocityX?: number, // 移动速度
|
236
|
-
// velocityY?: number, // 移动速度
|
237
|
-
// deltaX?: number, // X轴位移
|
238
|
-
// deltaY?: number, // Y轴位移
|
239
|
-
// timestamp: number, // 时间戳
|
240
|
-
// originEvent: Event, // 原始事件
|
241
|
-
// };
|
242
|
-
// 方向枚举
|
243
|
-
exports.GESTURE_DIRECTION = void 0;
|
244
|
-
(function (GESTURE_DIRECTION) {
|
245
|
-
GESTURE_DIRECTION[GESTURE_DIRECTION["NONE"] = 0] = "NONE";
|
246
|
-
GESTURE_DIRECTION[GESTURE_DIRECTION["ANY"] = 1] = "ANY";
|
247
|
-
// 滑动方向
|
248
|
-
GESTURE_DIRECTION[GESTURE_DIRECTION["UP"] = 2] = "UP";
|
249
|
-
GESTURE_DIRECTION[GESTURE_DIRECTION["DOWN"] = 3] = "DOWN";
|
250
|
-
GESTURE_DIRECTION[GESTURE_DIRECTION["LEFT"] = 4] = "LEFT";
|
251
|
-
GESTURE_DIRECTION[GESTURE_DIRECTION["RIGHT"] = 5] = "RIGHT";
|
252
|
-
// 缩放方向
|
253
|
-
GESTURE_DIRECTION[GESTURE_DIRECTION["IN"] = 6] = "IN";
|
254
|
-
GESTURE_DIRECTION[GESTURE_DIRECTION["OUT"] = 7] = "OUT";
|
255
|
-
// 旋转方向
|
256
|
-
GESTURE_DIRECTION[GESTURE_DIRECTION["CLOCKWISE"] = 8] = "CLOCKWISE";
|
257
|
-
GESTURE_DIRECTION[GESTURE_DIRECTION["COUNTERCLOCKWISE"] = 9] = "COUNTERCLOCKWISE";
|
258
|
-
})(exports.GESTURE_DIRECTION || (exports.GESTURE_DIRECTION = {}));
|
259
|
-
|
260
177
|
var _a$6, _b$3;
|
261
178
|
// @ts-expect-error safe to assign
|
262
179
|
var constants = {};
|
@@ -5996,611 +5913,7 @@ var MarsSharedGeometry = /** @class */ (function (_super) {
|
|
5996
5913
|
return MarsSharedGeometry;
|
5997
5914
|
}(MarsGeometry));
|
5998
5915
|
|
5999
|
-
|
6000
|
-
function WebHandler(system) {
|
6001
|
-
var _this = this;
|
6002
|
-
this.system = system;
|
6003
|
-
this.isPointerDown = false;
|
6004
|
-
this.handleStart = function (e) {
|
6005
|
-
_this.isPointerDown = true;
|
6006
|
-
_this.handleEvent(EVENT_TYPE_TOUCH_START, e);
|
6007
|
-
};
|
6008
|
-
this.handleMove = function (e) {
|
6009
|
-
if (_this.isPointerDown) {
|
6010
|
-
_this.handleEvent(EVENT_TYPE_TOUCH_MOVE, e);
|
6011
|
-
}
|
6012
|
-
};
|
6013
|
-
this.handleEnd = function (e) {
|
6014
|
-
_this.handleEvent(EVENT_TYPE_TOUCH_END, e);
|
6015
|
-
_this.isPointerDown = false;
|
6016
|
-
};
|
6017
|
-
this.pointers = new Map();
|
6018
|
-
this.timeOrigin = Date.now();
|
6019
|
-
}
|
6020
|
-
Object.defineProperty(WebHandler.prototype, "timeStamp", {
|
6021
|
-
get: function () {
|
6022
|
-
return Date.now() - this.timeOrigin;
|
6023
|
-
},
|
6024
|
-
enumerable: false,
|
6025
|
-
configurable: true
|
6026
|
-
});
|
6027
|
-
WebHandler.prototype.setup = function () {
|
6028
|
-
var target = this.system.target;
|
6029
|
-
target.addEventListener('pointerdown', this.handleStart);
|
6030
|
-
target.addEventListener('pointermove', this.handleMove);
|
6031
|
-
target.addEventListener('pointerup', this.handleEnd);
|
6032
|
-
};
|
6033
|
-
WebHandler.prototype.teardown = function () {
|
6034
|
-
var target = this.system.target;
|
6035
|
-
target.removeEventListener('pointerdown', this.handleStart);
|
6036
|
-
target.removeEventListener('pointermove', this.handleMove);
|
6037
|
-
target.removeEventListener('pointerup', this.handleEnd);
|
6038
|
-
};
|
6039
|
-
WebHandler.prototype.getNormalizedPos = function (e) {
|
6040
|
-
var rect = e.target.getBoundingClientRect();
|
6041
|
-
return [
|
6042
|
-
((e.clientX - rect.left) / rect.width) * 2 - 1,
|
6043
|
-
((e.clientY - rect.top) / rect.height) * -2 + 1,
|
6044
|
-
];
|
6045
|
-
};
|
6046
|
-
WebHandler.prototype.handleEvent = function (type, e) {
|
6047
|
-
e.preventDefault();
|
6048
|
-
// const np = this.getNormalizedPos(e);
|
6049
|
-
var rect = e.target.getBoundingClientRect();
|
6050
|
-
var pointer = {
|
6051
|
-
id: e.pointerId,
|
6052
|
-
x: e.clientX - rect.left,
|
6053
|
-
y: e.clientY - rect.top,
|
6054
|
-
ts: this.timeStamp,
|
6055
|
-
layout: {
|
6056
|
-
width: rect.width,
|
6057
|
-
height: rect.height,
|
6058
|
-
},
|
6059
|
-
};
|
6060
|
-
// 更新触点集合
|
6061
|
-
if (type === EVENT_TYPE_TOUCH_END) {
|
6062
|
-
this.pointers.delete(e.pointerId);
|
6063
|
-
}
|
6064
|
-
else {
|
6065
|
-
this.pointers.set(e.pointerId, pointer);
|
6066
|
-
}
|
6067
|
-
// 封装基础事件
|
6068
|
-
var event = {
|
6069
|
-
type: type,
|
6070
|
-
timestamp: this.timeStamp,
|
6071
|
-
target: e.target,
|
6072
|
-
touches: Array.from(this.pointers.values()),
|
6073
|
-
changedTouches: [pointer],
|
6074
|
-
preventDefault: function () { return e.preventDefault(); },
|
6075
|
-
stopPropagation: function () { return e.stopPropagation(); },
|
6076
|
-
nativeEvent: e,
|
6077
|
-
};
|
6078
|
-
this.system.handleBaseEvent(event);
|
6079
|
-
};
|
6080
|
-
return WebHandler;
|
6081
|
-
}());
|
6082
|
-
|
6083
|
-
var RNHandler = /** @class */ (function () {
|
6084
|
-
function RNHandler(system) {
|
6085
|
-
var _this = this;
|
6086
|
-
this.system = system;
|
6087
|
-
this.handleTouch = function (e) {
|
6088
|
-
e.preventDefault();
|
6089
|
-
_this.system.handleBaseEvent(e);
|
6090
|
-
};
|
6091
|
-
this.timeOrigin = Date.now();
|
6092
|
-
}
|
6093
|
-
Object.defineProperty(RNHandler.prototype, "timeStamp", {
|
6094
|
-
get: function () {
|
6095
|
-
return Date.now() - this.timeOrigin;
|
6096
|
-
},
|
6097
|
-
enumerable: false,
|
6098
|
-
configurable: true
|
6099
|
-
});
|
6100
|
-
RNHandler.prototype.setup = function () {
|
6101
|
-
var target = this.system.target;
|
6102
|
-
target.addEventListener('touchstart', this.handleTouch);
|
6103
|
-
target.addEventListener('touchmove', this.handleTouch);
|
6104
|
-
target.addEventListener('touchend', this.handleTouch);
|
6105
|
-
};
|
6106
|
-
RNHandler.prototype.teardown = function () {
|
6107
|
-
var target = this.system.target;
|
6108
|
-
target.removeEventListener('touchstart', this.handleTouch);
|
6109
|
-
target.removeEventListener('touchmove', this.handleTouch);
|
6110
|
-
target.removeEventListener('touchend', this.handleTouch);
|
6111
|
-
};
|
6112
|
-
return RNHandler;
|
6113
|
-
}());
|
6114
|
-
|
6115
|
-
var H5Handler = /** @class */ (function () {
|
6116
|
-
function H5Handler(system) {
|
6117
|
-
var _this = this;
|
6118
|
-
this.system = system;
|
6119
|
-
this.handleTouch = function (type, e) {
|
6120
|
-
e.preventDefault();
|
6121
|
-
// 封装基础事件
|
6122
|
-
var event = {
|
6123
|
-
type: type,
|
6124
|
-
timestamp: _this.timeStamp,
|
6125
|
-
// target: e.target,
|
6126
|
-
touches: _this.encapsulate(e.targetTouches),
|
6127
|
-
changedTouches: _this.encapsulate(e.changedTouches),
|
6128
|
-
preventDefault: function () { return e.preventDefault(); },
|
6129
|
-
stopPropagation: function () { return e.stopPropagation(); },
|
6130
|
-
nativeEvent: e,
|
6131
|
-
};
|
6132
|
-
_this.system.handleBaseEvent(event);
|
6133
|
-
};
|
6134
|
-
this.handleStart = function (e) { return _this.handleTouch(EVENT_TYPE_TOUCH_START, e); };
|
6135
|
-
this.handleMove = function (e) { return _this.handleTouch(EVENT_TYPE_TOUCH_MOVE, e); };
|
6136
|
-
this.handleEnd = function (e) { return _this.handleTouch(EVENT_TYPE_TOUCH_END, e); };
|
6137
|
-
this.timeOrigin = Date.now();
|
6138
|
-
}
|
6139
|
-
Object.defineProperty(H5Handler.prototype, "timeStamp", {
|
6140
|
-
get: function () {
|
6141
|
-
return Date.now() - this.timeOrigin;
|
6142
|
-
},
|
6143
|
-
enumerable: false,
|
6144
|
-
configurable: true
|
6145
|
-
});
|
6146
|
-
H5Handler.prototype.setup = function () {
|
6147
|
-
var target = this.system.target;
|
6148
|
-
target.addEventListener('touchstart', this.handleStart);
|
6149
|
-
target.addEventListener('touchmove', this.handleMove);
|
6150
|
-
target.addEventListener('touchend', this.handleEnd);
|
6151
|
-
target.addEventListener('touchcancel', this.handleEnd);
|
6152
|
-
};
|
6153
|
-
H5Handler.prototype.teardown = function () {
|
6154
|
-
var target = this.system.target;
|
6155
|
-
target.removeEventListener('touchstart', this.handleStart);
|
6156
|
-
target.removeEventListener('touchmove', this.handleMove);
|
6157
|
-
target.removeEventListener('touchend', this.handleEnd);
|
6158
|
-
target.removeEventListener('touchcancel', this.handleEnd);
|
6159
|
-
};
|
6160
|
-
H5Handler.prototype.getNormalizedPos = function (e) {
|
6161
|
-
var rect = e.target.getBoundingClientRect();
|
6162
|
-
return [
|
6163
|
-
((e.clientX - rect.left) / rect.width) * 2 - 1,
|
6164
|
-
((e.clientY - rect.top) / rect.height) * -2 + 1,
|
6165
|
-
];
|
6166
|
-
};
|
6167
|
-
H5Handler.prototype.encapsulate = function (list) {
|
6168
|
-
var touches = [];
|
6169
|
-
for (var i = 0; i < list.length; i++) {
|
6170
|
-
var touch = list[i];
|
6171
|
-
// const [x, y] = this.getNormalizedPos(touch);
|
6172
|
-
var rect = touch.target.getBoundingClientRect();
|
6173
|
-
touches.push({
|
6174
|
-
id: touch.identifier,
|
6175
|
-
x: touch.clientX - rect.left,
|
6176
|
-
y: touch.clientY - rect.top,
|
6177
|
-
ts: this.timeStamp,
|
6178
|
-
layout: {
|
6179
|
-
width: rect.width,
|
6180
|
-
height: rect.height,
|
6181
|
-
},
|
6182
|
-
});
|
6183
|
-
}
|
6184
|
-
return touches;
|
6185
|
-
};
|
6186
|
-
return H5Handler;
|
6187
|
-
}());
|
6188
|
-
|
6189
|
-
var UniversalRecognizer = /** @class */ (function () {
|
6190
|
-
function UniversalRecognizer(options) {
|
6191
|
-
this._state = exports.RecognizerState.UNDETERMINED;
|
6192
|
-
this.trackedTouches = new Map(); // 跟踪所有触点
|
6193
|
-
this.gestureStartTime = 0;
|
6194
|
-
this.startPositions = [];
|
6195
|
-
this.lastEventTs = 0;
|
6196
|
-
// 缩放/旋转专用缓存
|
6197
|
-
this.initialCenter = [0, 0];
|
6198
|
-
this.validateOptions(options);
|
6199
|
-
this.options = options;
|
6200
|
-
}
|
6201
|
-
Object.defineProperty(UniversalRecognizer.prototype, "state", {
|
6202
|
-
get: function () {
|
6203
|
-
return this._state;
|
6204
|
-
},
|
6205
|
-
enumerable: false,
|
6206
|
-
configurable: true
|
6207
|
-
});
|
6208
|
-
UniversalRecognizer.prototype.detect = function (event) {
|
6209
|
-
this.lastEventTs = event.timestamp;
|
6210
|
-
switch (event.type) {
|
6211
|
-
case 'touchstart':
|
6212
|
-
return this.handleStart(event);
|
6213
|
-
case 'touchmove':
|
6214
|
-
return this.handleMove(event);
|
6215
|
-
case 'touchend':
|
6216
|
-
case 'touchcancel':
|
6217
|
-
return this.handleEnd(event);
|
6218
|
-
}
|
6219
|
-
};
|
6220
|
-
UniversalRecognizer.prototype.trigger = function (event) {
|
6221
|
-
var _a;
|
6222
|
-
var type = this.getGestureName();
|
6223
|
-
(_a = this._callback) === null || _a === void 0 ? void 0 : _a.call(this, type, event);
|
6224
|
-
};
|
6225
|
-
UniversalRecognizer.prototype.handleStart = function (event) {
|
6226
|
-
var _this = this;
|
6227
|
-
if (this.state !== exports.RecognizerState.UNDETERMINED) {
|
6228
|
-
return;
|
6229
|
-
}
|
6230
|
-
// 验证触点数量
|
6231
|
-
if (event.touches.length !== this.options.touchCount) {
|
6232
|
-
this.reset();
|
6233
|
-
return;
|
6234
|
-
}
|
6235
|
-
// 初始化跟踪数据
|
6236
|
-
this.gestureStartTime = event.timestamp;
|
6237
|
-
this.trackedTouches.clear();
|
6238
|
-
event.touches.forEach(function (t) { return _this.trackedTouches.set(t.id, t); });
|
6239
|
-
this.startPositions = event.touches.map(function (t) { return [t.x, t.y]; });
|
6240
|
-
// 初始化多指手势数据
|
6241
|
-
if (this.options.touchCount > 1) {
|
6242
|
-
this.initialCenter = this.calculateCenter(event.touches);
|
6243
|
-
}
|
6244
|
-
this.setState(exports.RecognizerState.BEGAN);
|
6245
|
-
return this.getGestureName('start');
|
6246
|
-
};
|
6247
|
-
UniversalRecognizer.prototype.handleMove = function (event) {
|
6248
|
-
if (![exports.RecognizerState.BEGAN, exports.RecognizerState.ACTIVE].includes(this.state)) {
|
6249
|
-
return;
|
6250
|
-
}
|
6251
|
-
// 验证触点数量
|
6252
|
-
if (!this.validateTouchCount(event)) {
|
6253
|
-
this.reset();
|
6254
|
-
return;
|
6255
|
-
}
|
6256
|
-
// 验证时间区间
|
6257
|
-
if (!this.validateDuration(event)) {
|
6258
|
-
this.handleFailure();
|
6259
|
-
return;
|
6260
|
-
}
|
6261
|
-
// 验证距离区间
|
6262
|
-
if (!this.validateDistance(event)) {
|
6263
|
-
return;
|
6264
|
-
}
|
6265
|
-
// 方向/路径验证
|
6266
|
-
if (this.options.direction !== undefined) {
|
6267
|
-
if (!this.validateDirection(event)) {
|
6268
|
-
return;
|
6269
|
-
}
|
6270
|
-
}
|
6271
|
-
// 更新状态为持续活动
|
6272
|
-
if (this.state === exports.RecognizerState.BEGAN) {
|
6273
|
-
this.setState(exports.RecognizerState.ACTIVE);
|
6274
|
-
// return this.getGestureName('start');
|
6275
|
-
}
|
6276
|
-
return this.getGestureName('move');
|
6277
|
-
};
|
6278
|
-
UniversalRecognizer.prototype.handleEnd = function (event) {
|
6279
|
-
if (![exports.RecognizerState.BEGAN, exports.RecognizerState.ACTIVE].includes(this.state)) {
|
6280
|
-
return;
|
6281
|
-
}
|
6282
|
-
// 最终验证
|
6283
|
-
if (this.validateDuration(event)) {
|
6284
|
-
this.setState(exports.RecognizerState.END);
|
6285
|
-
if (this.validateThreshold(event)) {
|
6286
|
-
this.trigger(event);
|
6287
|
-
}
|
6288
|
-
return this.getGestureName('end');
|
6289
|
-
}
|
6290
|
-
else {
|
6291
|
-
this.handleFailure();
|
6292
|
-
}
|
6293
|
-
};
|
6294
|
-
/**
|
6295
|
-
* 手势识别核心算法
|
6296
|
-
*/
|
6297
|
-
UniversalRecognizer.prototype.validateTouchCount = function (event) {
|
6298
|
-
return event.touches.length === this.options.touchCount;
|
6299
|
-
};
|
6300
|
-
UniversalRecognizer.prototype.validateDuration = function (event) {
|
6301
|
-
var duration = event.timestamp - this.gestureStartTime;
|
6302
|
-
if (this.options.minDuration && duration < this.options.minDuration) {
|
6303
|
-
return false;
|
6304
|
-
}
|
6305
|
-
if (this.options.maxDuration && duration > this.options.maxDuration) {
|
6306
|
-
return false;
|
6307
|
-
}
|
6308
|
-
return true;
|
6309
|
-
};
|
6310
|
-
UniversalRecognizer.prototype.validateDistance = function (event) {
|
6311
|
-
var currentCenter = this.calculateCenter(event.touches);
|
6312
|
-
var startCenter = [0, 0];
|
6313
|
-
this.startPositions.forEach(function (pos) {
|
6314
|
-
startCenter[0] += pos[0];
|
6315
|
-
startCenter[1] += pos[1];
|
6316
|
-
});
|
6317
|
-
startCenter[0] /= this.startPositions.length;
|
6318
|
-
startCenter[1] /= this.startPositions.length;
|
6319
|
-
var distance = Math.hypot(currentCenter[0] - startCenter[0], currentCenter[1] - startCenter[1]);
|
6320
|
-
if (this.options.minDistance && distance < this.options.minDistance) {
|
6321
|
-
return false;
|
6322
|
-
}
|
6323
|
-
if (this.options.maxDistance && distance > this.options.maxDistance) {
|
6324
|
-
return false;
|
6325
|
-
}
|
6326
|
-
return true;
|
6327
|
-
};
|
6328
|
-
UniversalRecognizer.prototype.validateDirection = function (event) {
|
6329
|
-
return true;
|
6330
|
-
};
|
6331
|
-
UniversalRecognizer.prototype.validateThreshold = function (event) {
|
6332
|
-
var delta = this.calculateOverallDelta(event);
|
6333
|
-
switch (this.options.direction) {
|
6334
|
-
case exports.GESTURE_DIRECTION.LEFT:
|
6335
|
-
return delta[0] < -this.options.minDistance;
|
6336
|
-
case exports.GESTURE_DIRECTION.RIGHT:
|
6337
|
-
return delta[0] > this.options.minDistance;
|
6338
|
-
case exports.GESTURE_DIRECTION.UP:
|
6339
|
-
return delta[1] < -this.options.minDistance;
|
6340
|
-
case exports.GESTURE_DIRECTION.DOWN:
|
6341
|
-
return delta[1] > this.options.minDistance;
|
6342
|
-
case exports.GESTURE_DIRECTION.IN:
|
6343
|
-
return this.calculateScale(event.touches) < (1 - this.options.scaleThreshold);
|
6344
|
-
case exports.GESTURE_DIRECTION.OUT:
|
6345
|
-
return this.calculateScale(event.touches) > (1 + this.options.scaleThreshold);
|
6346
|
-
case exports.GESTURE_DIRECTION.CLOCKWISE:
|
6347
|
-
return this.calculateRotation(event.touches) > this.options.rotationThreshold;
|
6348
|
-
case exports.GESTURE_DIRECTION.COUNTERCLOCKWISE:
|
6349
|
-
return this.calculateRotation(event.touches) < -this.options.rotationThreshold;
|
6350
|
-
default:
|
6351
|
-
return true;
|
6352
|
-
}
|
6353
|
-
};
|
6354
|
-
UniversalRecognizer.prototype.calculateOverallDelta = function (event) {
|
6355
|
-
var _this = this;
|
6356
|
-
// 计算多点触控的平均移动量
|
6357
|
-
var totalDelta = [0, 0];
|
6358
|
-
event.touches.forEach(function (t, idx) {
|
6359
|
-
totalDelta[0] += t.x - _this.startPositions[idx][0];
|
6360
|
-
totalDelta[1] += t.y - _this.startPositions[idx][1];
|
6361
|
-
});
|
6362
|
-
return [totalDelta[0] / event.touches.length, totalDelta[1] / event.touches.length];
|
6363
|
-
};
|
6364
|
-
/**
|
6365
|
-
* 计算聚合缩放比例(基于各触点到中心点的距离变化)
|
6366
|
-
*/
|
6367
|
-
UniversalRecognizer.prototype.calculateScale = function (touches) {
|
6368
|
-
var _this = this;
|
6369
|
-
var currentCentroid = this.calculateCenter(touches);
|
6370
|
-
// 计算所有触点到中心点的平均距离
|
6371
|
-
var currentDistances = touches.map(function (t) {
|
6372
|
-
return Math.hypot(t.x - currentCentroid[0], t.y - currentCentroid[1]);
|
6373
|
-
});
|
6374
|
-
var currentAvgDistance = currentDistances.reduce(function (a, b) { return a + b; }) / touches.length;
|
6375
|
-
// 初始平均距离(从startPositions计算)
|
6376
|
-
var initialDistances = this.startPositions.map(function (pos) {
|
6377
|
-
return Math.hypot(pos[0] - _this.initialCenter[0], pos[1] - _this.initialCenter[1]);
|
6378
|
-
});
|
6379
|
-
var initialAvgDistance = initialDistances.reduce(function (a, b) { return a + b; }) / touches.length;
|
6380
|
-
return initialAvgDistance > 0 ? currentAvgDistance / initialAvgDistance : 1;
|
6381
|
-
};
|
6382
|
-
/**
|
6383
|
-
* 计算聚合旋转角度(基于各触点相对于中心点的角度变化)
|
6384
|
-
*/
|
6385
|
-
UniversalRecognizer.prototype.calculateRotation = function (touches) {
|
6386
|
-
var _this = this;
|
6387
|
-
var currentCentroid = this.calculateCenter(touches);
|
6388
|
-
var totalAngleChange = 0;
|
6389
|
-
touches.forEach(function (t, index) {
|
6390
|
-
// 当前触点角度
|
6391
|
-
var currentAngle = Math.atan2(t.y - currentCentroid[1], t.x - currentCentroid[0]);
|
6392
|
-
// 初始触点角度
|
6393
|
-
var initialPos = _this.startPositions[index];
|
6394
|
-
var initialAngle = Math.atan2(initialPos[1] - _this.initialCenter[1], initialPos[0] - _this.initialCenter[0]);
|
6395
|
-
// 累加角度变化(处理360°边界)
|
6396
|
-
var angleChange = currentAngle - initialAngle;
|
6397
|
-
if (angleChange > Math.PI) {
|
6398
|
-
angleChange -= 2 * Math.PI;
|
6399
|
-
}
|
6400
|
-
if (angleChange < -Math.PI) {
|
6401
|
-
angleChange += 2 * Math.PI;
|
6402
|
-
}
|
6403
|
-
totalAngleChange += angleChange;
|
6404
|
-
});
|
6405
|
-
// 转换为角度制并返回平均值
|
6406
|
-
return (totalAngleChange * 180 / Math.PI) / touches.length;
|
6407
|
-
};
|
6408
|
-
// 工具方法
|
6409
|
-
UniversalRecognizer.prototype.calculateCenter = function (touchList) {
|
6410
|
-
var pointersLength = touchList.length;
|
6411
|
-
if (pointersLength === 1) {
|
6412
|
-
return [touchList[0].x, touchList[0].y];
|
6413
|
-
}
|
6414
|
-
var x = 0;
|
6415
|
-
var y = 0;
|
6416
|
-
var i = 0;
|
6417
|
-
while (i < pointersLength) {
|
6418
|
-
x += touchList[i].x;
|
6419
|
-
y += touchList[i].y;
|
6420
|
-
i++;
|
6421
|
-
}
|
6422
|
-
return [x / pointersLength, y / pointersLength];
|
6423
|
-
};
|
6424
|
-
UniversalRecognizer.prototype.getGestureName = function (phase) {
|
6425
|
-
return phase ? "".concat(this.options.name).concat(phase) : this.options.name;
|
6426
|
-
};
|
6427
|
-
UniversalRecognizer.prototype.handleFailure = function () {
|
6428
|
-
this.setState(exports.RecognizerState.FAILED);
|
6429
|
-
this.reset();
|
6430
|
-
};
|
6431
|
-
/**
|
6432
|
-
* 重置所有状态
|
6433
|
-
*/
|
6434
|
-
UniversalRecognizer.prototype.reset = function () {
|
6435
|
-
this.trackedTouches.clear();
|
6436
|
-
this.startPositions = [];
|
6437
|
-
this.setState(exports.RecognizerState.UNDETERMINED);
|
6438
|
-
};
|
6439
|
-
UniversalRecognizer.prototype.setState = function (s) {
|
6440
|
-
this._state = s;
|
6441
|
-
};
|
6442
|
-
/**
|
6443
|
-
* 验证选项合规性,抛出详细错误信息
|
6444
|
-
*/
|
6445
|
-
UniversalRecognizer.prototype.validateOptions = function (options) {
|
6446
|
-
var errors = [];
|
6447
|
-
// 1. 基础必填字段检查
|
6448
|
-
if (!options.name || typeof options.name !== 'string') {
|
6449
|
-
errors.push('Missing or invalid `name`: must be a non-empty string');
|
6450
|
-
}
|
6451
|
-
if (typeof options.touchCount !== 'number' ||
|
6452
|
-
options.touchCount < 1 ||
|
6453
|
-
options.touchCount > 5 ||
|
6454
|
-
!Number.isInteger(options.touchCount)) {
|
6455
|
-
errors.push('Invalid `touchCount`: must be an integer of [1, 5]');
|
6456
|
-
}
|
6457
|
-
// 2. 方向相关检查
|
6458
|
-
if (options.direction !== undefined) {
|
6459
|
-
if (!Object.values(exports.GESTURE_DIRECTION).includes(options.direction)) {
|
6460
|
-
errors.push("Invalid `moveDirection`: ".concat(options.direction, " is not a valid GESTURE_DIRECTION enum"));
|
6461
|
-
}
|
6462
|
-
// 当方向为NONE时,必须检查点击次数
|
6463
|
-
if (options.direction === exports.GESTURE_DIRECTION.NONE) {
|
6464
|
-
if (options.clickCount === undefined) {
|
6465
|
-
errors.push('Missing `clickCount` when direction is NONE');
|
6466
|
-
}
|
6467
|
-
else if (typeof options.clickCount !== 'number' || options.clickCount < 1) {
|
6468
|
-
errors.push('Invalid `clickCount`: must be a positive integer');
|
6469
|
-
}
|
6470
|
-
}
|
6471
|
-
}
|
6472
|
-
// 3. 时间区间检查
|
6473
|
-
this.validateRange('duration', options.minDuration, options.maxDuration, 'Time duration range invalid', errors);
|
6474
|
-
// 4. 距离区间检查
|
6475
|
-
this.validateRange('distance', options.minDistance, options.maxDistance, 'Distance range invalid', errors);
|
6476
|
-
// 5. 高级参数检查
|
6477
|
-
if (options.scaleThreshold !== undefined) {
|
6478
|
-
if (options.touchCount < 2) {
|
6479
|
-
errors.push('`scaleThreshold` requires touchCount>=2');
|
6480
|
-
}
|
6481
|
-
else if (options.scaleThreshold <= 0) {
|
6482
|
-
errors.push('`scaleThreshold` must be positive');
|
6483
|
-
}
|
6484
|
-
}
|
6485
|
-
if (options.rotationThreshold !== undefined) {
|
6486
|
-
if (options.touchCount < 2) {
|
6487
|
-
errors.push('`rotationThreshold` requires touchCount>=2');
|
6488
|
-
}
|
6489
|
-
else if (options.rotationThreshold <= 0) {
|
6490
|
-
errors.push('`rotationThreshold` must be positive');
|
6491
|
-
}
|
6492
|
-
}
|
6493
|
-
// 6. 互斥参数检查
|
6494
|
-
if (options.direction !== undefined && options.customPath !== undefined) {
|
6495
|
-
errors.push('`moveDirection` and `customPath` cannot coexist');
|
6496
|
-
}
|
6497
|
-
// 抛出所有错误
|
6498
|
-
if (errors.length > 0) {
|
6499
|
-
throw new Error("Invalid options for \"".concat(options.name, "\":\n- ").concat(errors.join('\n- ')));
|
6500
|
-
}
|
6501
|
-
};
|
6502
|
-
/**
|
6503
|
-
* 通用区间验证工具
|
6504
|
-
*/
|
6505
|
-
UniversalRecognizer.prototype.validateRange = function (field, min, max, errorMsg, errors) {
|
6506
|
-
if (min !== undefined && min < 0) {
|
6507
|
-
errors.push("Invalid `min".concat(field, "`: must be non-negative"));
|
6508
|
-
}
|
6509
|
-
if (max !== undefined && max < 0) {
|
6510
|
-
errors.push("Invalid `max".concat(field, "`: must be non-negative"));
|
6511
|
-
}
|
6512
|
-
if (min !== undefined && max !== undefined && min > max) {
|
6513
|
-
errors.push("".concat(errorMsg, ": min (").concat(min, ") > max (").concat(max, ")"));
|
6514
|
-
}
|
6515
|
-
};
|
6516
|
-
return UniversalRecognizer;
|
6517
|
-
}());
|
6518
|
-
|
6519
|
-
var PredyEventSystem = /** @class */ (function () {
|
6520
|
-
function PredyEventSystem(target, env) {
|
6521
|
-
this._handlerMap = new Map();
|
6522
|
-
this._enabled = true;
|
6523
|
-
this.target = target;
|
6524
|
-
this._platformHandler = this.createPlatformHandler(env);
|
6525
|
-
this._platformHandler.setup();
|
6526
|
-
this.setRecognizer(new BaseRecognizer());
|
6527
|
-
}
|
6528
|
-
Object.defineProperty(PredyEventSystem.prototype, "enabled", {
|
6529
|
-
get: function () {
|
6530
|
-
return this._enabled;
|
6531
|
-
},
|
6532
|
-
set: function (value) {
|
6533
|
-
this._enabled = value;
|
6534
|
-
},
|
6535
|
-
enumerable: false,
|
6536
|
-
configurable: true
|
6537
|
-
});
|
6538
|
-
PredyEventSystem.prototype.createPlatformHandler = function (env) {
|
6539
|
-
switch (env) {
|
6540
|
-
case exports.EventSystemEnv.web:
|
6541
|
-
return new WebHandler(this);
|
6542
|
-
case exports.EventSystemEnv.rn:
|
6543
|
-
return new RNHandler(this);
|
6544
|
-
case exports.EventSystemEnv.h5:
|
6545
|
-
return new H5Handler(this);
|
6546
|
-
default:
|
6547
|
-
throw new Error("Unsupported platform ".concat(env));
|
6548
|
-
}
|
6549
|
-
};
|
6550
|
-
PredyEventSystem.prototype.setRecognizer = function (recognizer) {
|
6551
|
-
recognizer._callback = this.dispatch.bind(this);
|
6552
|
-
this.recognizer = recognizer;
|
6553
|
-
};
|
6554
|
-
PredyEventSystem.prototype.setUniversalRecognizer = function (options) {
|
6555
|
-
var r = new UniversalRecognizer(options);
|
6556
|
-
this.setRecognizer(r);
|
6557
|
-
};
|
6558
|
-
// 事件分发入口
|
6559
|
-
PredyEventSystem.prototype.handleBaseEvent = function (event) {
|
6560
|
-
if (!this.enabled) {
|
6561
|
-
return;
|
6562
|
-
}
|
6563
|
-
// 识别手势
|
6564
|
-
var gestureType = this.recognizer.detect(event);
|
6565
|
-
if (gestureType) {
|
6566
|
-
this.dispatch(gestureType, event);
|
6567
|
-
}
|
6568
|
-
if (event.touches.length === 0) {
|
6569
|
-
this.recognizer.reset();
|
6570
|
-
}
|
6571
|
-
};
|
6572
|
-
PredyEventSystem.prototype.dispatch = function (type, event) {
|
6573
|
-
var _a;
|
6574
|
-
(_a = this._handlerMap.get(type)) === null || _a === void 0 ? void 0 : _a.forEach(function (fn) { return fn(event); });
|
6575
|
-
};
|
6576
|
-
PredyEventSystem.prototype.addEventListener = function (type, handler) {
|
6577
|
-
var _this = this;
|
6578
|
-
var set = this._handlerMap.get(type) || new Set();
|
6579
|
-
set.add(handler);
|
6580
|
-
this._handlerMap.set(type, set);
|
6581
|
-
return function () { return _this.removeEventListener(type, handler); };
|
6582
|
-
};
|
6583
|
-
PredyEventSystem.prototype.removeEventListener = function (type, handler) {
|
6584
|
-
var _a;
|
6585
|
-
(_a = this._handlerMap.get(type)) === null || _a === void 0 ? void 0 : _a.delete(handler);
|
6586
|
-
};
|
6587
|
-
PredyEventSystem.prototype.destroy = function () {
|
6588
|
-
this._platformHandler.teardown();
|
6589
|
-
this._handlerMap.clear();
|
6590
|
-
};
|
6591
|
-
return PredyEventSystem;
|
6592
|
-
}());
|
6593
|
-
var BaseRecognizer = /** @class */ (function () {
|
6594
|
-
function BaseRecognizer() {
|
6595
|
-
}
|
6596
|
-
BaseRecognizer.prototype.detect = function (event) {
|
6597
|
-
return event.type;
|
6598
|
-
};
|
6599
|
-
BaseRecognizer.prototype.reset = function () { };
|
6600
|
-
return BaseRecognizer;
|
6601
|
-
}());
|
6602
|
-
|
6603
|
-
consoleLog('version: ' + "0.3.4-beta.17");
|
5916
|
+
consoleLog('version: ' + "0.3.4-beta.19");
|
6604
5917
|
var ModuleMsg = 'RI Package: @predy-js/render-interface';
|
6605
5918
|
|
6606
5919
|
var RI = /*#__PURE__*/Object.freeze({
|
@@ -6621,7 +5934,6 @@ var RI = /*#__PURE__*/Object.freeze({
|
|
6621
5934
|
getDefaultTextureFactory: getDefaultTextureFactory,
|
6622
5935
|
setDefaultTextureFactory: setDefaultTextureFactory,
|
6623
5936
|
MarsTextureFactory: MarsTextureFactory,
|
6624
|
-
EventSystem: PredyEventSystem,
|
6625
5937
|
get DestroyOptions () { return exports.DestroyOptions; },
|
6626
5938
|
get PredyTextEncoding () { return exports.PredyTextEncoding; },
|
6627
5939
|
get PredyVideoCodec () { return exports.PredyVideoCodec; },
|
@@ -6636,15 +5948,6 @@ var RI = /*#__PURE__*/Object.freeze({
|
|
6636
5948
|
get RenderPassMeshOrder () { return exports.RenderPassMeshOrder; },
|
6637
5949
|
get TextureSourceType () { return exports.TextureSourceType; },
|
6638
5950
|
GPUBufferOptionsMemoryShared: GPUBufferOptionsMemoryShared,
|
6639
|
-
get EventSystemEnv () { return exports.EventSystemEnv; },
|
6640
|
-
get RecognizerState () { return exports.RecognizerState; },
|
6641
|
-
EVENT_TYPE_CLICK: EVENT_TYPE_CLICK,
|
6642
|
-
EVENT_TYPE_TOUCH_START: EVENT_TYPE_TOUCH_START,
|
6643
|
-
EVENT_TYPE_TOUCH_MOVE: EVENT_TYPE_TOUCH_MOVE,
|
6644
|
-
EVENT_TYPE_TOUCH_END: EVENT_TYPE_TOUCH_END,
|
6645
|
-
EVENT_TYPE_TOUCH_CANCEL: EVENT_TYPE_TOUCH_CANCEL,
|
6646
|
-
get PredyNativeEventType () { return exports.PredyNativeEventType; },
|
6647
|
-
get GESTURE_DIRECTION () { return exports.GESTURE_DIRECTION; },
|
6648
5951
|
get ShaderCompileResultStatus () { return exports.ShaderCompileResultStatus; },
|
6649
5952
|
ShaderLibraryEmpty: ShaderLibraryEmpty
|
6650
5953
|
});
|
@@ -6656,12 +5959,6 @@ else if (typeof global === 'object') {
|
|
6656
5959
|
global.PredyRI = RI;
|
6657
5960
|
}
|
6658
5961
|
|
6659
|
-
exports.EVENT_TYPE_CLICK = EVENT_TYPE_CLICK;
|
6660
|
-
exports.EVENT_TYPE_TOUCH_CANCEL = EVENT_TYPE_TOUCH_CANCEL;
|
6661
|
-
exports.EVENT_TYPE_TOUCH_END = EVENT_TYPE_TOUCH_END;
|
6662
|
-
exports.EVENT_TYPE_TOUCH_MOVE = EVENT_TYPE_TOUCH_MOVE;
|
6663
|
-
exports.EVENT_TYPE_TOUCH_START = EVENT_TYPE_TOUCH_START;
|
6664
|
-
exports.EventSystem = PredyEventSystem;
|
6665
5962
|
exports.GPUBufferOptionsMemoryShared = GPUBufferOptionsMemoryShared;
|
6666
5963
|
exports.Geometry = MarsGeometry;
|
6667
5964
|
exports.InstancedMesh = MarsInstancedMesh;
|