@predy-js/render-interface 0.3.4-beta.14 → 0.3.4-beta.16
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 +63 -65
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +64 -66
- package/dist/index.mjs.map +1 -1
- package/dist/src/render/event/RNHandler.d.ts +1 -0
- package/dist/src/render/event/UniversalRecognizer.d.ts +0 -2
- package/dist/statistic.js +1 -1
- package/dist/types/EventSystem.d.ts +11 -6
- package/dist/types/native/GPUBufferInternal.d.ts +1 -0
- package/dist/types/native/PredyNativeInternal.d.ts +2 -0
- package/dist/types/native/index.d.ts +1 -0
- package/dist/types/native/motion.d.ts +20 -0
- package/package.json +1 -1
- package/types/EventSystem.ts +14 -7
- package/types/native/DataBlockInternal.ts +3 -0
- package/types/native/GPUBufferInternal.ts +1 -0
- package/types/native/PredyNativeInternal.ts +4 -0
- package/types/native/index.ts +1 -0
- package/types/native/motion.ts +26 -0
package/dist/index.mjs
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.16
|
6
6
|
*/
|
7
7
|
|
8
8
|
/******************************************************************************
|
@@ -193,6 +193,12 @@ var EVENT_TYPE_TOUCH_START = 'touchstart';
|
|
193
193
|
var EVENT_TYPE_TOUCH_MOVE = 'touchmove';
|
194
194
|
var EVENT_TYPE_TOUCH_END = 'touchend';
|
195
195
|
var EVENT_TYPE_TOUCH_CANCEL = 'touchcancel';
|
196
|
+
var PredyNativeEventType;
|
197
|
+
(function (PredyNativeEventType) {
|
198
|
+
PredyNativeEventType[PredyNativeEventType["touchstart"] = 1] = "touchstart";
|
199
|
+
PredyNativeEventType[PredyNativeEventType["touchmove"] = 2] = "touchmove";
|
200
|
+
PredyNativeEventType[PredyNativeEventType["touchend"] = 3] = "touchend";
|
201
|
+
})(PredyNativeEventType || (PredyNativeEventType = {}));
|
196
202
|
// // 扩展事件类型
|
197
203
|
// export enum EVENT_TYPE {
|
198
204
|
// // 基础事件
|
@@ -6035,15 +6041,17 @@ var WebHandler = /** @class */ (function () {
|
|
6035
6041
|
};
|
6036
6042
|
WebHandler.prototype.handleEvent = function (type, e) {
|
6037
6043
|
e.preventDefault();
|
6038
|
-
|
6044
|
+
// const np = this.getNormalizedPos(e);
|
6045
|
+
var rect = e.target.getBoundingClientRect();
|
6039
6046
|
var pointer = {
|
6040
6047
|
id: e.pointerId,
|
6041
|
-
x:
|
6042
|
-
y:
|
6043
|
-
clientX: e.clientX,
|
6044
|
-
clientY: e.clientY,
|
6045
|
-
force: 1,
|
6048
|
+
x: e.clientX - rect.left,
|
6049
|
+
y: e.clientY - rect.top,
|
6046
6050
|
ts: this.timeStamp,
|
6051
|
+
layout: {
|
6052
|
+
width: rect.width,
|
6053
|
+
height: rect.height,
|
6054
|
+
},
|
6047
6055
|
};
|
6048
6056
|
// 更新触点集合
|
6049
6057
|
if (type === EVENT_TYPE_TOUCH_END) {
|
@@ -6070,7 +6078,12 @@ var WebHandler = /** @class */ (function () {
|
|
6070
6078
|
|
6071
6079
|
var RNHandler = /** @class */ (function () {
|
6072
6080
|
function RNHandler(system) {
|
6081
|
+
var _this = this;
|
6073
6082
|
this.system = system;
|
6083
|
+
this.handleTouch = function (e) {
|
6084
|
+
e.preventDefault();
|
6085
|
+
_this.system.handleBaseEvent(e);
|
6086
|
+
};
|
6074
6087
|
this.timeOrigin = Date.now();
|
6075
6088
|
}
|
6076
6089
|
Object.defineProperty(RNHandler.prototype, "timeStamp", {
|
@@ -6081,10 +6094,16 @@ var RNHandler = /** @class */ (function () {
|
|
6081
6094
|
configurable: true
|
6082
6095
|
});
|
6083
6096
|
RNHandler.prototype.setup = function () {
|
6084
|
-
|
6097
|
+
var target = this.system.target;
|
6098
|
+
target.addEventListener('touchstart', this.handleTouch);
|
6099
|
+
target.addEventListener('touchmove', this.handleTouch);
|
6100
|
+
target.addEventListener('touchend', this.handleTouch);
|
6085
6101
|
};
|
6086
6102
|
RNHandler.prototype.teardown = function () {
|
6087
|
-
|
6103
|
+
var target = this.system.target;
|
6104
|
+
target.removeEventListener('touchstart', this.handleTouch);
|
6105
|
+
target.removeEventListener('touchmove', this.handleTouch);
|
6106
|
+
target.removeEventListener('touchend', this.handleTouch);
|
6088
6107
|
};
|
6089
6108
|
return RNHandler;
|
6090
6109
|
}());
|
@@ -6099,7 +6118,7 @@ var H5Handler = /** @class */ (function () {
|
|
6099
6118
|
var event = {
|
6100
6119
|
type: type,
|
6101
6120
|
timestamp: _this.timeStamp,
|
6102
|
-
target: e.target,
|
6121
|
+
// target: e.target,
|
6103
6122
|
touches: _this.encapsulate(e.targetTouches),
|
6104
6123
|
changedTouches: _this.encapsulate(e.changedTouches),
|
6105
6124
|
preventDefault: function () { return e.preventDefault(); },
|
@@ -6145,15 +6164,17 @@ var H5Handler = /** @class */ (function () {
|
|
6145
6164
|
var touches = [];
|
6146
6165
|
for (var i = 0; i < list.length; i++) {
|
6147
6166
|
var touch = list[i];
|
6148
|
-
|
6167
|
+
// const [x, y] = this.getNormalizedPos(touch);
|
6168
|
+
var rect = touch.target.getBoundingClientRect();
|
6149
6169
|
touches.push({
|
6150
6170
|
id: touch.identifier,
|
6151
|
-
x:
|
6152
|
-
y:
|
6153
|
-
clientX: touch.clientX,
|
6154
|
-
clientY: touch.clientY,
|
6155
|
-
force: 1,
|
6171
|
+
x: touch.clientX - rect.left,
|
6172
|
+
y: touch.clientY - rect.top,
|
6156
6173
|
ts: this.timeStamp,
|
6174
|
+
layout: {
|
6175
|
+
width: rect.width,
|
6176
|
+
height: rect.height,
|
6177
|
+
},
|
6157
6178
|
});
|
6158
6179
|
}
|
6159
6180
|
return touches;
|
@@ -6211,7 +6232,7 @@ var UniversalRecognizer = /** @class */ (function () {
|
|
6211
6232
|
this.gestureStartTime = event.timestamp;
|
6212
6233
|
this.trackedTouches.clear();
|
6213
6234
|
event.touches.forEach(function (t) { return _this.trackedTouches.set(t.id, t); });
|
6214
|
-
this.startPositions = event.touches.map(function (t) { return [t.
|
6235
|
+
this.startPositions = event.touches.map(function (t) { return [t.x, t.y]; });
|
6215
6236
|
// 初始化多指手势数据
|
6216
6237
|
if (this.options.touchCount > 1) {
|
6217
6238
|
this.initialCenter = this.calculateCenter(event.touches);
|
@@ -6223,16 +6244,26 @@ var UniversalRecognizer = /** @class */ (function () {
|
|
6223
6244
|
if (![RecognizerState.BEGAN, RecognizerState.ACTIVE].includes(this.state)) {
|
6224
6245
|
return;
|
6225
6246
|
}
|
6226
|
-
//
|
6227
|
-
if (
|
6247
|
+
// 验证触点数量
|
6248
|
+
if (!this.validateTouchCount(event)) {
|
6228
6249
|
this.reset();
|
6229
6250
|
return;
|
6230
6251
|
}
|
6231
|
-
//
|
6232
|
-
if (!this.
|
6252
|
+
// 验证时间区间
|
6253
|
+
if (!this.validateDuration(event)) {
|
6233
6254
|
this.handleFailure();
|
6234
6255
|
return;
|
6235
6256
|
}
|
6257
|
+
// 验证距离区间
|
6258
|
+
if (!this.validateDistance(event)) {
|
6259
|
+
return;
|
6260
|
+
}
|
6261
|
+
// 方向/路径验证
|
6262
|
+
if (this.options.direction !== undefined) {
|
6263
|
+
if (!this.validateDirection(event)) {
|
6264
|
+
return;
|
6265
|
+
}
|
6266
|
+
}
|
6236
6267
|
// 更新状态为持续活动
|
6237
6268
|
if (this.state === RecognizerState.BEGAN) {
|
6238
6269
|
this.setState(RecognizerState.ACTIVE);
|
@@ -6244,9 +6275,8 @@ var UniversalRecognizer = /** @class */ (function () {
|
|
6244
6275
|
if (![RecognizerState.BEGAN, RecognizerState.ACTIVE].includes(this.state)) {
|
6245
6276
|
return;
|
6246
6277
|
}
|
6247
|
-
//
|
6248
|
-
|
6249
|
-
if (isValid) {
|
6278
|
+
// 最终验证
|
6279
|
+
if (this.validateDuration(event)) {
|
6250
6280
|
this.setState(RecognizerState.END);
|
6251
6281
|
if (this.validateThreshold(event)) {
|
6252
6282
|
this.trigger(event);
|
@@ -6260,26 +6290,6 @@ var UniversalRecognizer = /** @class */ (function () {
|
|
6260
6290
|
/**
|
6261
6291
|
* 手势识别核心算法
|
6262
6292
|
*/
|
6263
|
-
UniversalRecognizer.prototype.validateGesture = function (event) {
|
6264
|
-
// 基础验证
|
6265
|
-
if (!this.validateTouchCount(event)) {
|
6266
|
-
return false;
|
6267
|
-
}
|
6268
|
-
if (!this.validateDuration(event)) {
|
6269
|
-
return false;
|
6270
|
-
}
|
6271
|
-
if (!this.validateDistance(event)) {
|
6272
|
-
return false;
|
6273
|
-
}
|
6274
|
-
// 方向/路径验证
|
6275
|
-
if (this.options.direction !== undefined) {
|
6276
|
-
if (!this.validateDirection(event)) {
|
6277
|
-
return false;
|
6278
|
-
}
|
6279
|
-
}
|
6280
|
-
// 高级手势验证
|
6281
|
-
return true;
|
6282
|
-
};
|
6283
6293
|
UniversalRecognizer.prototype.validateTouchCount = function (event) {
|
6284
6294
|
return event.touches.length === this.options.touchCount;
|
6285
6295
|
};
|
@@ -6337,26 +6347,13 @@ var UniversalRecognizer = /** @class */ (function () {
|
|
6337
6347
|
return true;
|
6338
6348
|
}
|
6339
6349
|
};
|
6340
|
-
UniversalRecognizer.prototype.validateFinalConditions = function (event) {
|
6341
|
-
// 验证时间区间
|
6342
|
-
var duration = event.timestamp - this.gestureStartTime;
|
6343
|
-
if (this.options.minDuration && duration < this.options.minDuration) {
|
6344
|
-
return false;
|
6345
|
-
}
|
6346
|
-
if (this.options.maxDuration && duration > this.options.maxDuration) {
|
6347
|
-
return false;
|
6348
|
-
}
|
6349
|
-
// 验证点击次数(需要外部状态管理)
|
6350
|
-
// 此处需要结合外部计数器实现双击等逻辑
|
6351
|
-
return true;
|
6352
|
-
};
|
6353
6350
|
UniversalRecognizer.prototype.calculateOverallDelta = function (event) {
|
6354
6351
|
var _this = this;
|
6355
6352
|
// 计算多点触控的平均移动量
|
6356
6353
|
var totalDelta = [0, 0];
|
6357
6354
|
event.touches.forEach(function (t, idx) {
|
6358
|
-
totalDelta[0] += t.
|
6359
|
-
totalDelta[1] += t.
|
6355
|
+
totalDelta[0] += t.x - _this.startPositions[idx][0];
|
6356
|
+
totalDelta[1] += t.y - _this.startPositions[idx][1];
|
6360
6357
|
});
|
6361
6358
|
return [totalDelta[0] / event.touches.length, totalDelta[1] / event.touches.length];
|
6362
6359
|
};
|
@@ -6368,7 +6365,7 @@ var UniversalRecognizer = /** @class */ (function () {
|
|
6368
6365
|
var currentCentroid = this.calculateCenter(touches);
|
6369
6366
|
// 计算所有触点到中心点的平均距离
|
6370
6367
|
var currentDistances = touches.map(function (t) {
|
6371
|
-
return Math.hypot(t.
|
6368
|
+
return Math.hypot(t.x - currentCentroid[0], t.y - currentCentroid[1]);
|
6372
6369
|
});
|
6373
6370
|
var currentAvgDistance = currentDistances.reduce(function (a, b) { return a + b; }) / touches.length;
|
6374
6371
|
// 初始平均距离(从startPositions计算)
|
@@ -6387,7 +6384,7 @@ var UniversalRecognizer = /** @class */ (function () {
|
|
6387
6384
|
var totalAngleChange = 0;
|
6388
6385
|
touches.forEach(function (t, index) {
|
6389
6386
|
// 当前触点角度
|
6390
|
-
var currentAngle = Math.atan2(t.
|
6387
|
+
var currentAngle = Math.atan2(t.y - currentCentroid[1], t.x - currentCentroid[0]);
|
6391
6388
|
// 初始触点角度
|
6392
6389
|
var initialPos = _this.startPositions[index];
|
6393
6390
|
var initialAngle = Math.atan2(initialPos[1] - _this.initialCenter[1], initialPos[0] - _this.initialCenter[0]);
|
@@ -6408,14 +6405,14 @@ var UniversalRecognizer = /** @class */ (function () {
|
|
6408
6405
|
UniversalRecognizer.prototype.calculateCenter = function (touchList) {
|
6409
6406
|
var pointersLength = touchList.length;
|
6410
6407
|
if (pointersLength === 1) {
|
6411
|
-
return [touchList[0].
|
6408
|
+
return [touchList[0].x, touchList[0].y];
|
6412
6409
|
}
|
6413
6410
|
var x = 0;
|
6414
6411
|
var y = 0;
|
6415
6412
|
var i = 0;
|
6416
6413
|
while (i < pointersLength) {
|
6417
|
-
x += touchList[i].
|
6418
|
-
y += touchList[i].
|
6414
|
+
x += touchList[i].x;
|
6415
|
+
y += touchList[i].y;
|
6419
6416
|
i++;
|
6420
6417
|
}
|
6421
6418
|
return [x / pointersLength, y / pointersLength];
|
@@ -6599,7 +6596,7 @@ var BaseRecognizer = /** @class */ (function () {
|
|
6599
6596
|
return BaseRecognizer;
|
6600
6597
|
}());
|
6601
6598
|
|
6602
|
-
consoleLog('version: ' + "0.3.4-beta.
|
6599
|
+
consoleLog('version: ' + "0.3.4-beta.16");
|
6603
6600
|
var ModuleMsg = 'RI Package: @predy-js/render-interface';
|
6604
6601
|
|
6605
6602
|
var RI = /*#__PURE__*/Object.freeze({
|
@@ -6642,6 +6639,7 @@ var RI = /*#__PURE__*/Object.freeze({
|
|
6642
6639
|
EVENT_TYPE_TOUCH_MOVE: EVENT_TYPE_TOUCH_MOVE,
|
6643
6640
|
EVENT_TYPE_TOUCH_END: EVENT_TYPE_TOUCH_END,
|
6644
6641
|
EVENT_TYPE_TOUCH_CANCEL: EVENT_TYPE_TOUCH_CANCEL,
|
6642
|
+
get PredyNativeEventType () { return PredyNativeEventType; },
|
6645
6643
|
get GESTURE_DIRECTION () { return GESTURE_DIRECTION; },
|
6646
6644
|
get ShaderCompileResultStatus () { return ShaderCompileResultStatus; },
|
6647
6645
|
ShaderLibraryEmpty: ShaderLibraryEmpty
|
@@ -6654,5 +6652,5 @@ else if (typeof global === 'object') {
|
|
6654
6652
|
global.PredyRI = RI;
|
6655
6653
|
}
|
6656
6654
|
|
6657
|
-
export { DestroyOptions, EVENT_TYPE_CLICK, EVENT_TYPE_TOUCH_CANCEL, EVENT_TYPE_TOUCH_END, EVENT_TYPE_TOUCH_MOVE, EVENT_TYPE_TOUCH_START, PredyEventSystem as EventSystem, EventSystemEnv, GESTURE_DIRECTION, GPUBufferOptionsMemoryShared, MarsGeometry as Geometry, MarsInstancedMesh as InstancedMesh, MarsTextureFactory, MarsMaterial as Material, MarsMaterialDataBlock as MaterialDataBlock, MarsMesh as Mesh, ModuleMsg, PredyResourceCacheStatus, PredyTextEncoding, PredyVideoCodec, RecognizerState, MarsRenderFrame as RenderFrame, MarsRenderPass as RenderPass, RenderPassAttachmentStorageType, RenderPassDestroyAttachmentType, RenderPassMeshOrder, RenderPassPriorityNormal, RenderPassPriorityPostprocess, RenderPassPriorityPrepare, MarsRenderer as Renderer, ShaderCompileResultStatus, ShaderLibraryEmpty, MarsSharedGeometry as SharedGeometry, MarsTexture as Texture, TextureLoadAction, TextureSourceType, TextureStoreAction, constants, getDefaultGPUCapability, getDefaultTextureFactory, setDefaultTextureFactory };
|
6655
|
+
export { DestroyOptions, EVENT_TYPE_CLICK, EVENT_TYPE_TOUCH_CANCEL, EVENT_TYPE_TOUCH_END, EVENT_TYPE_TOUCH_MOVE, EVENT_TYPE_TOUCH_START, PredyEventSystem as EventSystem, EventSystemEnv, GESTURE_DIRECTION, GPUBufferOptionsMemoryShared, MarsGeometry as Geometry, MarsInstancedMesh as InstancedMesh, MarsTextureFactory, MarsMaterial as Material, MarsMaterialDataBlock as MaterialDataBlock, MarsMesh as Mesh, ModuleMsg, PredyNativeEventType, PredyResourceCacheStatus, PredyTextEncoding, PredyVideoCodec, RecognizerState, MarsRenderFrame as RenderFrame, MarsRenderPass as RenderPass, RenderPassAttachmentStorageType, RenderPassDestroyAttachmentType, RenderPassMeshOrder, RenderPassPriorityNormal, RenderPassPriorityPostprocess, RenderPassPriorityPrepare, MarsRenderer as Renderer, ShaderCompileResultStatus, ShaderLibraryEmpty, MarsSharedGeometry as SharedGeometry, MarsTexture as Texture, TextureLoadAction, TextureSourceType, TextureStoreAction, constants, getDefaultGPUCapability, getDefaultTextureFactory, setDefaultTextureFactory };
|
6658
6656
|
//# sourceMappingURL=index.mjs.map
|